summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiang Wang <xwxw@google.com>2023-09-14 10:11:15 -0700
committerXiang Wang <xwxw@google.com>2023-09-15 00:48:59 +0000
commitc16a0484ae5173500682e711288e0297c0c1ba36 (patch)
treed9a4f62dd4c7d536ba95936ff3c4e80f66be373e
parent37a37ff8c9bcf451c1266d9573894769b07b27b3 (diff)
downloadpixel-c16a0484ae5173500682e711288e0297c0c1ba36.tar.gz
Check thermal callback and binder health before async callback
Fix the looper to signal abort and join the background thread so it can deconstruct cleanly without sigabort in case thermal hal dies. Bug: b/291986991 Test: atest PtsThermalHalTestCases VtsHalThermalTargetTest libthermaltest Change-Id: I7197c7343e0f9861ded245173003b8ae9b9ee793 Merged-In: I7197c7343e0f9861ded245173003b8ae9b9ee793
-rw-r--r--thermal/Android.bp179
-rw-r--r--thermal/Thermal.cpp122
-rw-r--r--thermal/Thermal.h6
-rw-r--r--thermal/tests/mock_thermal_helper.cpp24
-rw-r--r--thermal/tests/mock_thermal_helper.h71
-rw-r--r--thermal/tests/thermal_looper_test.cpp96
-rw-r--r--thermal/thermal-helper.cpp80
-rw-r--r--thermal/thermal-helper.h91
8 files changed, 485 insertions, 184 deletions
diff --git a/thermal/Android.bp b/thermal/Android.bp
index 86f6cb69..61403b31 100644
--- a/thermal/Android.bp
+++ b/thermal/Android.bp
@@ -3,80 +3,119 @@ package {
}
cc_binary {
- name: "android.hardware.thermal-service.pixel",
- srcs: [
- "service.cpp",
- "Thermal.cpp",
- "thermal-helper.cpp",
- "utils/thermal_throttling.cpp",
- "utils/thermal_info.cpp",
- "utils/thermal_files.cpp",
- "utils/power_files.cpp",
- "utils/powerhal_helper.cpp",
- "utils/thermal_stats_helper.cpp",
- "utils/thermal_watcher.cpp",
- ],
- vendor: true,
- relative_install_path: "hw",
- vintf_fragments: [
- "android.hardware.thermal-service.pixel.xml"
- ],
- init_rc: [
- "android.hardware.thermal-service.pixel.rc",
- ],
- shared_libs: [
- "libbase",
- "libcutils",
- "libjsoncpp",
- "libutils",
- "libnl",
- "libbinder_ndk",
- "android.frameworks.stats-V1-ndk",
- "android.hardware.power-V1-ndk",
- "android.hardware.thermal-V1-ndk",
- "pixel-power-ext-V1-ndk",
- "pixelatoms-cpp",
- ],
- static_libs: [
- "libpixelstats",
- ],
- export_shared_lib_headers: [
- "android.frameworks.stats-V1-ndk",
- "pixelatoms-cpp",
- ],
- cflags: [
- "-Wall",
- "-Werror",
- "-Wextra",
- "-Wunused",
- ],
- tidy: true,
- tidy_checks: [
- "android-*",
- "cert-*",
- "clang-analyzer-security*",
- ],
- tidy_checks_as_errors: [
- "android-*",
- "clang-analyzer-security*",
- "cert-*",
- ],
+ name: "android.hardware.thermal-service.pixel",
+ srcs: [
+ "service.cpp",
+ "Thermal.cpp",
+ "thermal-helper.cpp",
+ "utils/thermal_throttling.cpp",
+ "utils/thermal_info.cpp",
+ "utils/thermal_files.cpp",
+ "utils/power_files.cpp",
+ "utils/powerhal_helper.cpp",
+ "utils/thermal_stats_helper.cpp",
+ "utils/thermal_watcher.cpp",
+ ],
+ vendor: true,
+ relative_install_path: "hw",
+ vintf_fragments: [
+ "android.hardware.thermal-service.pixel.xml",
+ ],
+ init_rc: [
+ "android.hardware.thermal-service.pixel.rc",
+ ],
+ shared_libs: [
+ "libbase",
+ "libcutils",
+ "libjsoncpp",
+ "libutils",
+ "libnl",
+ "libbinder_ndk",
+ "android.frameworks.stats-V1-ndk",
+ "android.hardware.power-V1-ndk",
+ "android.hardware.thermal-V1-ndk",
+ "pixel-power-ext-V1-ndk",
+ "pixelatoms-cpp",
+ ],
+ static_libs: [
+ "libpixelstats",
+ ],
+ export_shared_lib_headers: [
+ "android.frameworks.stats-V1-ndk",
+ "pixelatoms-cpp",
+ ],
+ cflags: [
+ "-Wall",
+ "-Werror",
+ "-Wextra",
+ "-Wunused",
+ ],
+ tidy: true,
+ tidy_checks: [
+ "android-*",
+ "cert-*",
+ "clang-analyzer-security*",
+ ],
+ tidy_checks_as_errors: [
+ "android-*",
+ "clang-analyzer-security*",
+ "cert-*",
+ ],
+}
+
+cc_test {
+ name: "libthermaltest",
+ vendor: true,
+ srcs: [
+ "service.cpp",
+ "Thermal.cpp",
+ "thermal-helper.cpp",
+ "utils/thermal_throttling.cpp",
+ "utils/thermal_info.cpp",
+ "utils/thermal_files.cpp",
+ "utils/power_files.cpp",
+ "utils/powerhal_helper.cpp",
+ "utils/thermal_stats_helper.cpp",
+ "utils/thermal_watcher.cpp",
+ "tests/mock_thermal_helper.cpp",
+ "tests/thermal_looper_test.cpp",
+ ],
+ shared_libs: [
+ "libbase",
+ "libcutils",
+ "libjsoncpp",
+ "libutils",
+ "libnl",
+ "liblog",
+ "libbinder_ndk",
+ "android.frameworks.stats-V1-ndk",
+ "android.hardware.power-V1-ndk",
+ "android.hardware.thermal-V1-ndk",
+ "pixel-power-ext-V1-ndk",
+ "pixelatoms-cpp",
+ ],
+ static_libs: [
+ "libgmock",
+ "libpixelstats",
+ ],
+ test_suites: ["device-tests"],
+ require_root: true,
}
sh_binary {
- name: "thermal_logd",
- src: "init.thermal.logging.sh",
- vendor: true,
- init_rc: [
- "pixel-thermal-logd.rc",
- ],
+ name: "thermal_logd",
+ src: "init.thermal.logging.sh",
+ vendor: true,
+ init_rc: [
+ "pixel-thermal-logd.rc",
+ ],
}
sh_binary {
- name: "thermal_symlinks",
- src: "init.thermal.symlinks.sh",
- vendor: true,
- init_rc: [
- "pixel-thermal-symlinks.rc",
- ],
+ name: "thermal_symlinks",
+ src: "init.thermal.symlinks.sh",
+ vendor: true,
+ init_rc: [
+ "pixel-thermal-symlinks.rc",
+ ],
}
diff --git a/thermal/Thermal.cpp b/thermal/Thermal.cpp
index 0d533d3e..2ae963ec 100644
--- a/thermal/Thermal.cpp
+++ b/thermal/Thermal.cpp
@@ -50,9 +50,14 @@ bool interfacesEqual(const std::shared_ptr<::ndk::ICInterface> left,
} // namespace
-Thermal::Thermal()
- : thermal_helper_(
- std::bind(&Thermal::sendThermalChangedCallback, this, std::placeholders::_1)) {}
+Thermal::Thermal() {
+ thermal_helper_ = std::make_shared<ThermalHelperImpl>(
+ std::bind(&Thermal::sendThermalChangedCallback, this, std::placeholders::_1));
+}
+
+Thermal::Thermal(const std::shared_ptr<ThermalHelper> &helper) {
+ thermal_helper_ = helper;
+}
ndk::ScopedAStatus Thermal::getTemperatures(std::vector<Temperature> *_aidl_return) {
return getFilteredTemperatures(false, TemperatureType::UNKNOWN, _aidl_return);
@@ -66,10 +71,10 @@ ndk::ScopedAStatus Thermal::getTemperaturesWithType(TemperatureType type,
ndk::ScopedAStatus Thermal::getFilteredTemperatures(bool filterType, TemperatureType type,
std::vector<Temperature> *_aidl_return) {
*_aidl_return = {};
- if (!thermal_helper_.isInitializedOk()) {
+ if (!thermal_helper_->isInitializedOk()) {
return initErrorStatus();
}
- if (!thermal_helper_.fillCurrentTemperatures(filterType, false, type, _aidl_return)) {
+ if (!thermal_helper_->fillCurrentTemperatures(filterType, false, type, _aidl_return)) {
return readErrorStatus();
}
return ndk::ScopedAStatus::ok();
@@ -87,10 +92,10 @@ ndk::ScopedAStatus Thermal::getCoolingDevicesWithType(CoolingType type,
ndk::ScopedAStatus Thermal::getFilteredCoolingDevices(bool filterType, CoolingType type,
std::vector<CoolingDevice> *_aidl_return) {
*_aidl_return = {};
- if (!thermal_helper_.isInitializedOk()) {
+ if (!thermal_helper_->isInitializedOk()) {
return initErrorStatus();
}
- if (!thermal_helper_.fillCurrentCoolingDevices(filterType, type, _aidl_return)) {
+ if (!thermal_helper_->fillCurrentCoolingDevices(filterType, type, _aidl_return)) {
return readErrorStatus();
}
return ndk::ScopedAStatus::ok();
@@ -110,10 +115,10 @@ ndk::ScopedAStatus Thermal::getTemperatureThresholdsWithType(
ndk::ScopedAStatus Thermal::getFilteredTemperatureThresholds(
bool filterType, TemperatureType type, std::vector<TemperatureThreshold> *_aidl_return) {
*_aidl_return = {};
- if (!thermal_helper_.isInitializedOk()) {
+ if (!thermal_helper_->isInitializedOk()) {
return initErrorStatus();
}
- if (!thermal_helper_.fillTemperatureThresholds(filterType, type, _aidl_return)) {
+ if (!thermal_helper_->fillTemperatureThresholds(filterType, type, _aidl_return)) {
return readErrorStatus();
}
return ndk::ScopedAStatus::ok();
@@ -168,7 +173,7 @@ ndk::ScopedAStatus Thermal::registerThermalChangedCallback(
return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
"Invalid nullptr callback");
}
- if (!thermal_helper_.isInitializedOk()) {
+ if (!thermal_helper_->isInitializedOk()) {
return initErrorStatus();
}
std::lock_guard<std::mutex> _lock(thermal_callback_mutex_);
@@ -184,14 +189,25 @@ ndk::ScopedAStatus Thermal::registerThermalChangedCallback(
// Send notification right away after successful thermal callback registration
std::function<void()> handler = [this, c, filterType, type]() {
std::vector<Temperature> temperatures;
- if (thermal_helper_.fillCurrentTemperatures(filterType, true, type, &temperatures)) {
- for (const auto &t : temperatures) {
- if (!filterType || t.type == type) {
- LOG(INFO) << "Sending notification: "
- << " Type: " << toString(t.type) << " Name: " << t.name
- << " CurrentValue: " << t.value
- << " ThrottlingStatus: " << toString(t.throttlingStatus);
- c.callback->notifyThrottling(t);
+ if (thermal_helper_->fillCurrentTemperatures(filterType, true, type, &temperatures)) {
+ std::lock_guard<std::mutex> _lock(thermal_callback_mutex_);
+ auto it = std::find_if(callbacks_.begin(), callbacks_.end(),
+ [&](const CallbackSetting &cc) {
+ return interfacesEqual(c.callback, cc.callback);
+ });
+ if (it != callbacks_.end()) {
+ if (AIBinder_isAlive(c.callback->asBinder().get())) {
+ for (const auto &t : temperatures) {
+ if (!filterType || t.type == type) {
+ LOG(INFO) << "Sending notification: "
+ << " Type: " << toString(t.type) << " Name: " << t.name
+ << " CurrentValue: " << t.value
+ << " ThrottlingStatus: " << toString(t.throttlingStatus);
+ c.callback->notifyThrottling(t);
+ }
+ }
+ } else {
+ callbacks_.erase(it);
}
}
}
@@ -227,7 +243,7 @@ void Thermal::sendThermalChangedCallback(const Temperature &t) {
void Thermal::dumpVirtualSensorInfo(std::ostringstream *dump_buf) {
*dump_buf << "getVirtualSensorInfo:" << std::endl;
- const auto &map = thermal_helper_.GetSensorInfoMap();
+ const auto &map = thermal_helper_->GetSensorInfoMap();
for (const auto &sensor_info_pair : map) {
if (sensor_info_pair.second.virtual_sensor_info != nullptr) {
*dump_buf << " Name: " << sensor_info_pair.first << std::endl;
@@ -282,8 +298,8 @@ void Thermal::dumpVirtualSensorInfo(std::ostringstream *dump_buf) {
void Thermal::dumpThrottlingInfo(std::ostringstream *dump_buf) {
*dump_buf << "getThrottlingInfo:" << std::endl;
- const auto &map = thermal_helper_.GetSensorInfoMap();
- const auto &thermal_throttling_status_map = thermal_helper_.GetThermalThrottlingStatusMap();
+ const auto &map = thermal_helper_->GetSensorInfoMap();
+ const auto &thermal_throttling_status_map = thermal_helper_->GetThermalThrottlingStatusMap();
for (const auto &name_info_pair : map) {
if (name_info_pair.second.throttling_info == nullptr) {
continue;
@@ -416,7 +432,7 @@ void Thermal::dumpThrottlingInfo(std::ostringstream *dump_buf) {
}
void Thermal::dumpThrottlingRequestStatus(std::ostringstream *dump_buf) {
- const auto &thermal_throttling_status_map = thermal_helper_.GetThermalThrottlingStatusMap();
+ const auto &thermal_throttling_status_map = thermal_helper_->GetThermalThrottlingStatusMap();
if (!thermal_throttling_status_map.size()) {
return;
}
@@ -466,8 +482,8 @@ void Thermal::dumpThrottlingRequestStatus(std::ostringstream *dump_buf) {
}
void Thermal::dumpPowerRailInfo(std::ostringstream *dump_buf) {
- const auto &power_rail_info_map = thermal_helper_.GetPowerRailInfoMap();
- const auto &power_status_map = thermal_helper_.GetPowerStatusMap();
+ const auto &power_rail_info_map = thermal_helper_->GetPowerRailInfoMap();
+ const auto &power_status_map = thermal_helper_->GetPowerStatusMap();
*dump_buf << "getPowerRailInfo:" << std::endl;
for (const auto &power_rail_pair : power_rail_info_map) {
@@ -545,7 +561,7 @@ void Thermal::dumpStatsRecord(std::ostringstream *dump_buf, const StatsRecord &s
void Thermal::dumpThermalStats(std::ostringstream *dump_buf) {
*dump_buf << "getThermalStatsInfo:" << std::endl;
*dump_buf << " Sensor Temp Stats Info:" << std::endl;
- const auto &sensor_temp_stats_map_ = thermal_helper_.GetSensorTempStatsSnapshot();
+ const auto &sensor_temp_stats_map_ = thermal_helper_->GetSensorTempStatsSnapshot();
const std::string sensor_temp_stats_line_prefix(" ");
for (const auto &sensor_temp_stats_pair : sensor_temp_stats_map_) {
*dump_buf << " Sensor Name: " << sensor_temp_stats_pair.first << std::endl;
@@ -576,7 +592,7 @@ void Thermal::dumpThermalStats(std::ostringstream *dump_buf) {
}
*dump_buf << " Sensor Cdev Request Stats Info:" << std::endl;
const auto &sensor_cdev_request_stats_map_ =
- thermal_helper_.GetSensorCoolingDeviceRequestStatsSnapshot();
+ thermal_helper_->GetSensorCoolingDeviceRequestStatsSnapshot();
const std::string sensor_cdev_request_stats_line_prefix(" ");
for (const auto &sensor_cdev_request_stats_pair : sensor_cdev_request_stats_map_) {
*dump_buf << " Sensor Name: " << sensor_cdev_request_stats_pair.first << std::endl;
@@ -608,10 +624,10 @@ void Thermal::dumpThermalStats(std::ostringstream *dump_buf) {
void Thermal::dumpThermalData(int fd) {
std::ostringstream dump_buf;
- if (!thermal_helper_.isInitializedOk()) {
+ if (!thermal_helper_->isInitializedOk()) {
dump_buf << "ThermalHAL not initialized properly." << std::endl;
} else {
- const auto &sensor_status_map = thermal_helper_.GetSensorStatusMap();
+ const auto &sensor_status_map = thermal_helper_->GetSensorStatusMap();
{
dump_buf << "getCachedTemperatures:" << std::endl;
boot_clock::time_point now = boot_clock::now();
@@ -642,11 +658,11 @@ void Thermal::dumpThermalData(int fd) {
}
}
{
- const auto &map = thermal_helper_.GetSensorInfoMap();
+ const auto &map = thermal_helper_->GetSensorInfoMap();
dump_buf << "getCurrentTemperatures:" << std::endl;
Temperature temp_2_0;
for (const auto &name_info_pair : map) {
- thermal_helper_.readTemperature(name_info_pair.first, &temp_2_0, nullptr, true);
+ thermal_helper_->readTemperature(name_info_pair.first, &temp_2_0, nullptr, true);
dump_buf << " Type: " << toString(temp_2_0.type)
<< " Name: " << name_info_pair.first << " CurrentValue: " << temp_2_0.value
<< " ThrottlingStatus: " << toString(temp_2_0.throttlingStatus)
@@ -690,8 +706,8 @@ void Thermal::dumpThermalData(int fd) {
{
dump_buf << "getCurrentCoolingDevices:" << std::endl;
std::vector<CoolingDevice> cooling_devices;
- if (!thermal_helper_.fillCurrentCoolingDevices(false, CoolingType::CPU,
- &cooling_devices)) {
+ if (!thermal_helper_->fillCurrentCoolingDevices(false, CoolingType::CPU,
+ &cooling_devices)) {
dump_buf << " Failed to getCurrentCoolingDevices." << std::endl;
}
@@ -711,7 +727,7 @@ void Thermal::dumpThermalData(int fd) {
{
dump_buf << "sendCallback:" << std::endl;
dump_buf << " Enabled List: ";
- const auto &map = thermal_helper_.GetSensorInfoMap();
+ const auto &map = thermal_helper_->GetSensorInfoMap();
for (const auto &name_info_pair : map) {
if (name_info_pair.second.send_cb) {
dump_buf << name_info_pair.first << " ";
@@ -722,7 +738,7 @@ void Thermal::dumpThermalData(int fd) {
{
dump_buf << "sendPowerHint:" << std::endl;
dump_buf << " Enabled List: ";
- const auto &map = thermal_helper_.GetSensorInfoMap();
+ const auto &map = thermal_helper_->GetSensorInfoMap();
for (const auto &name_info_pair : map) {
if (name_info_pair.second.send_powerhint) {
dump_buf << name_info_pair.first << " ";
@@ -737,12 +753,12 @@ void Thermal::dumpThermalData(int fd) {
dumpThermalStats(&dump_buf);
{
dump_buf << "getAIDLPowerHalInfo:" << std::endl;
- dump_buf << " Exist: " << std::boolalpha << thermal_helper_.isAidlPowerHalExist()
+ dump_buf << " Exist: " << std::boolalpha << thermal_helper_->isAidlPowerHalExist()
<< std::endl;
- dump_buf << " Connected: " << std::boolalpha << thermal_helper_.isPowerHalConnected()
+ dump_buf << " Connected: " << std::boolalpha << thermal_helper_->isPowerHalConnected()
<< std::endl;
dump_buf << " Ext connected: " << std::boolalpha
- << thermal_helper_.isPowerHalExtConnected() << std::endl;
+ << thermal_helper_->isPowerHalExtConnected() << std::endl;
}
}
std::string buf = dump_buf.str();
@@ -759,17 +775,18 @@ binder_status_t Thermal::dump(int fd, const char **args, uint32_t numArgs) {
}
if (std::string(args[0]) == "emul_temp") {
- return (numArgs != 3 || !thermal_helper_.emulTemp(std::string(args[1]), std::atof(args[2])))
+ return (numArgs != 3 || !thermal_helper_->emulTemp(std::string(args[1]), std::atof(args[2])))
? STATUS_BAD_VALUE
: STATUS_OK;
} else if (std::string(args[0]) == "emul_severity") {
return (numArgs != 3 ||
- !thermal_helper_.emulSeverity(std::string(args[1]), std::atoi(args[2])))
+ !thermal_helper_->emulSeverity(std::string(args[1]), std::atoi(args[2])))
? STATUS_BAD_VALUE
: STATUS_OK;
} else if (std::string(args[0]) == "emul_clear") {
- return (numArgs != 2 || !thermal_helper_.emulClear(std::string(args[1]))) ? STATUS_BAD_VALUE
- : STATUS_OK;
+ return (numArgs != 2 || !thermal_helper_->emulClear(std::string(args[1])))
+ ? STATUS_BAD_VALUE
+ : STATUS_OK;
}
return STATUS_BAD_VALUE;
}
@@ -780,14 +797,25 @@ void Thermal::Looper::addEvent(const Thermal::Looper::Event &e) {
cv_.notify_all();
}
+Thermal::Looper::~Looper() {
+ {
+ std::unique_lock<std::mutex> lock(mutex_);
+ aborted_ = true;
+ }
+ cv_.notify_one();
+ thread_.join();
+}
+
void Thermal::Looper::loop() {
- while (true) {
+ while (!aborted_) {
std::unique_lock<std::mutex> lock(mutex_);
- cv_.wait(lock, [&] { return !events_.empty(); });
- Event event = events_.front();
- events_.pop();
- lock.unlock();
- event.handler();
+ cv_.wait(lock, [&] { return aborted_ || !events_.empty(); });
+ if (!aborted_ && !events_.empty()) {
+ Event event = events_.front();
+ events_.pop();
+ lock.unlock();
+ event.handler();
+ }
}
}
diff --git a/thermal/Thermal.h b/thermal/Thermal.h
index 74449c4e..f8f9c63a 100644
--- a/thermal/Thermal.h
+++ b/thermal/Thermal.h
@@ -41,6 +41,7 @@ struct CallbackSetting {
class Thermal : public BnThermal {
public:
Thermal();
+ explicit Thermal(const std::shared_ptr<ThermalHelper> &helper);
~Thermal() = default;
ndk::ScopedAStatus getTemperatures(std::vector<Temperature> *_aidl_return) override;
ndk::ScopedAStatus getTemperaturesWithType(TemperatureType type,
@@ -77,6 +78,8 @@ class Thermal : public BnThermal {
Looper() {
thread_ = std::thread([&] { loop(); });
}
+ ~Looper();
+
void addEvent(const Event &e);
private:
@@ -84,11 +87,12 @@ class Thermal : public BnThermal {
std::queue<Event> events_;
std::mutex mutex_;
std::thread thread_;
+ bool aborted_;
void loop();
};
- ThermalHelper thermal_helper_;
+ std::shared_ptr<ThermalHelper> thermal_helper_;
std::mutex thermal_callback_mutex_;
std::vector<CallbackSetting> callbacks_;
Looper looper_;
diff --git a/thermal/tests/mock_thermal_helper.cpp b/thermal/tests/mock_thermal_helper.cpp
new file mode 100644
index 00000000..358371d4
--- /dev/null
+++ b/thermal/tests/mock_thermal_helper.cpp
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2023 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.
+ */
+
+#include "mock_thermal_helper.h"
+
+namespace aidl::android::hardware::thermal::implementation {
+
+MockThermalHelper::MockThermalHelper() = default;
+MockThermalHelper::~MockThermalHelper() = default;
+
+} // namespace aidl::android::hardware::thermal::implementation
diff --git a/thermal/tests/mock_thermal_helper.h b/thermal/tests/mock_thermal_helper.h
new file mode 100644
index 00000000..a089ed67
--- /dev/null
+++ b/thermal/tests/mock_thermal_helper.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2023 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.
+ */
+
+#include <aidl/android/hardware/thermal/IThermal.h>
+#include <gmock/gmock.h>
+#include <log/log.h>
+
+#include <unordered_map>
+
+#include "thermal-helper.h"
+
+namespace aidl::android::hardware::thermal::implementation {
+
+class MockThermalHelper : public ThermalHelper {
+ public:
+ MockThermalHelper();
+ ~MockThermalHelper() override;
+ MOCK_METHOD(bool, fillCurrentTemperatures,
+ (bool, bool, TemperatureType, std::vector<Temperature> *), (override));
+ MOCK_METHOD(bool, fillTemperatureThresholds,
+ (bool, TemperatureType, std::vector<TemperatureThreshold> *), (const, override));
+ MOCK_METHOD(bool, fillCurrentCoolingDevices, (bool, CoolingType, std::vector<CoolingDevice> *),
+ (const, override));
+ MOCK_METHOD(bool, emulTemp, (std::string_view, const float), (override));
+ MOCK_METHOD(bool, emulSeverity, (std::string_view, const int), (override));
+ MOCK_METHOD(bool, emulClear, (std::string_view), (override));
+ MOCK_METHOD(bool, isInitializedOk, (), (const, override));
+ MOCK_METHOD(bool, readTemperature,
+ (std::string_view, Temperature *out,
+ (std::pair<ThrottlingSeverity, ThrottlingSeverity> *), const bool),
+ (override));
+ MOCK_METHOD(bool, readTemperatureThreshold, (std::string_view, TemperatureThreshold *),
+ (const, override));
+ MOCK_METHOD(bool, readCoolingDevice, (std::string_view, CoolingDevice *), (const, override));
+ MOCK_METHOD((const std::unordered_map<std::string, SensorInfo> &), GetSensorInfoMap, (),
+ (const, override));
+ MOCK_METHOD((const std::unordered_map<std::string, CdevInfo> &), GetCdevInfoMap, (),
+ (const, override));
+ MOCK_METHOD((const std::unordered_map<std::string, SensorStatus> &), GetSensorStatusMap, (),
+ (const, override));
+ MOCK_METHOD((const std::unordered_map<std::string, ThermalThrottlingStatus> &),
+ GetThermalThrottlingStatusMap, (), (const, override));
+ MOCK_METHOD((const std::unordered_map<std::string, PowerRailInfo> &), GetPowerRailInfoMap, (),
+ (const, override));
+ MOCK_METHOD((const std::unordered_map<std::string, PowerStatus> &), GetPowerStatusMap, (),
+ (const, override));
+ MOCK_METHOD((const std::unordered_map<std::string, SensorTempStats>),
+ GetSensorTempStatsSnapshot, (), (override));
+ MOCK_METHOD((const std::unordered_map<std::string,
+ std::unordered_map<std::string, ThermalStats<int>>>),
+ GetSensorCoolingDeviceRequestStatsSnapshot, (), (override));
+ MOCK_METHOD(void, sendPowerExtHint, (const Temperature &), (override));
+ MOCK_METHOD(bool, isAidlPowerHalExist, (), (override));
+ MOCK_METHOD(bool, isPowerHalConnected, (), (override));
+ MOCK_METHOD(bool, isPowerHalExtConnected, (), (override));
+};
+
+} // namespace aidl::android::hardware::thermal::implementation
diff --git a/thermal/tests/thermal_looper_test.cpp b/thermal/tests/thermal_looper_test.cpp
new file mode 100644
index 00000000..65f13d13
--- /dev/null
+++ b/thermal/tests/thermal_looper_test.cpp
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2023 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.
+ */
+
+#include <aidl/android/hardware/thermal/BnThermalChangedCallback.h>
+#include <log/log.h>
+
+#include "Thermal.h"
+#include "mock_thermal_helper.h"
+
+namespace aidl::android::hardware::thermal::implementation {
+
+class ThermalLooperTest : public testing::Test {
+ protected:
+ void SetUp() override {
+ ON_CALL(*helper, isInitializedOk).WillByDefault(testing::Return(true));
+ }
+
+ std::shared_ptr<testing::NiceMock<MockThermalHelper>> helper =
+ std::make_shared<testing::NiceMock<MockThermalHelper>>();
+ std::shared_ptr<Thermal> thermal = ndk::SharedRefBase::make<Thermal>(helper);
+};
+
+class TestCallback : public BnThermalChangedCallback {
+ public:
+ ndk::ScopedAStatus notifyThrottling(const Temperature &t) override {
+ std::lock_guard<std::mutex> lock_guard(mMutex);
+ mTemperatures.emplace_back(t);
+ return ndk::ScopedAStatus::ok();
+ }
+
+ std::vector<Temperature> getTemperatures() {
+ std::lock_guard<std::mutex> lock_guard(mMutex);
+ return mTemperatures;
+ }
+
+ void clear() {
+ std::lock_guard<std::mutex> lock_guard(mMutex);
+ mTemperatures.clear();
+ }
+
+ private:
+ std::vector<Temperature> mTemperatures;
+ std::mutex mMutex;
+};
+
+TEST_F(ThermalLooperTest, AsyncCallbackTest) {
+ Temperature t1;
+ t1.type = TemperatureType::SKIN;
+ Temperature t2;
+ t2.type = TemperatureType::UNKNOWN;
+ ON_CALL(*helper, fillCurrentTemperatures)
+ .WillByDefault([this, t1, t2](bool, bool, TemperatureType,
+ std::vector<Temperature> *temperatures) {
+ std::vector<Temperature> ret = {t1, t2};
+ *temperatures = ret;
+ sleep(1);
+ return true;
+ });
+ std::shared_ptr<TestCallback> callback = ndk::SharedRefBase::make<TestCallback>();
+ std::shared_ptr<TestCallback> callbackWithType = ndk::SharedRefBase::make<TestCallback>();
+
+ // if callback immediately unregistered, no async callback should be scheduled
+ ASSERT_TRUE(thermal->registerThermalChangedCallback(callback).isOk());
+ ASSERT_TRUE(
+ thermal->registerThermalChangedCallbackWithType(callbackWithType, TemperatureType::SKIN)
+ .isOk());
+ ASSERT_TRUE(thermal->unregisterThermalChangedCallback(callback).isOk());
+ ASSERT_TRUE(thermal->unregisterThermalChangedCallback(callbackWithType).isOk());
+ sleep(3);
+ ASSERT_TRUE(callback->getTemperatures().empty());
+ ASSERT_TRUE(callbackWithType->getTemperatures().empty());
+
+ // otherwise, async callback should be scheduled if registered
+ ASSERT_TRUE(thermal->registerThermalChangedCallback(callback).isOk());
+ ASSERT_TRUE(
+ thermal->registerThermalChangedCallbackWithType(callbackWithType, TemperatureType::SKIN)
+ .isOk());
+ sleep(3);
+ ASSERT_THAT(callback->getTemperatures(), testing::UnorderedElementsAreArray({t1, t2}));
+ ASSERT_THAT(callbackWithType->getTemperatures(), testing::UnorderedElementsAreArray({t1}));
+}
+
+} // namespace aidl::android::hardware::thermal::implementation
diff --git a/thermal/thermal-helper.cpp b/thermal/thermal-helper.cpp
index 87e362ad..a8281e0b 100644
--- a/thermal/thermal-helper.cpp
+++ b/thermal/thermal-helper.cpp
@@ -93,7 +93,7 @@ std::unordered_map<std::string, std::string> parseThermalPathMap(std::string_vie
} // namespace
// If the cdev_ceiling is higher than CDEV max_state, cap the cdev_ceiling to max_state.
-void ThermalHelper::maxCoolingRequestCheck(
+void ThermalHelperImpl::maxCoolingRequestCheck(
std::unordered_map<std::string, BindedCdevInfo> *binded_cdev_info_map) {
for (auto &binded_cdev_info_pair : *binded_cdev_info_map) {
const auto &cdev_info = cooling_device_info_map_.at(binded_cdev_info_pair.first);
@@ -114,9 +114,9 @@ void ThermalHelper::maxCoolingRequestCheck(
* reading the type file and assigning the temp file path to the map. If we do
* not succeed, abort.
*/
-ThermalHelper::ThermalHelper(const NotificationCallback &cb)
- : thermal_watcher_(new ThermalWatcher(
- std::bind(&ThermalHelper::thermalWatcherCallbackFunc, this, std::placeholders::_1))),
+ThermalHelperImpl::ThermalHelperImpl(const NotificationCallback &cb)
+ : thermal_watcher_(new ThermalWatcher(std::bind(&ThermalHelperImpl::thermalWatcherCallbackFunc,
+ this, std::placeholders::_1))),
cb_(cb) {
const std::string config_path =
"/vendor/etc/" +
@@ -293,7 +293,7 @@ bool getThermalZoneTypeById(int tz_id, std::string *type) {
return true;
}
-bool ThermalHelper::emulTemp(std::string_view target_sensor, const float value) {
+bool ThermalHelperImpl::emulTemp(std::string_view target_sensor, const float value) {
LOG(INFO) << "Set " << target_sensor.data() << " emul_temp "
<< "to " << value;
@@ -311,7 +311,7 @@ bool ThermalHelper::emulTemp(std::string_view target_sensor, const float value)
return true;
}
-bool ThermalHelper::emulSeverity(std::string_view target_sensor, const int severity) {
+bool ThermalHelperImpl::emulSeverity(std::string_view target_sensor, const int severity) {
LOG(INFO) << "Set " << target_sensor.data() << " emul_severity "
<< "to " << severity;
@@ -334,7 +334,7 @@ bool ThermalHelper::emulSeverity(std::string_view target_sensor, const int sever
return true;
}
-bool ThermalHelper::emulClear(std::string_view target_sensor) {
+bool ThermalHelperImpl::emulClear(std::string_view target_sensor) {
LOG(INFO) << "Clear " << target_sensor.data() << " emulation settings";
std::lock_guard<std::shared_mutex> _lock(sensor_status_map_mutex_);
@@ -355,7 +355,8 @@ bool ThermalHelper::emulClear(std::string_view target_sensor) {
return true;
}
-bool ThermalHelper::readCoolingDevice(std::string_view cooling_device, CoolingDevice *out) const {
+bool ThermalHelperImpl::readCoolingDevice(std::string_view cooling_device,
+ CoolingDevice *out) const {
// Read the file. If the file can't be read temp will be empty string.
std::string data;
@@ -374,7 +375,7 @@ bool ThermalHelper::readCoolingDevice(std::string_view cooling_device, CoolingDe
return true;
}
-bool ThermalHelper::readTemperature(
+bool ThermalHelperImpl::readTemperature(
std::string_view sensor_name, Temperature *out,
std::pair<ThrottlingSeverity, ThrottlingSeverity> *throttling_status,
const bool force_no_cache) {
@@ -436,8 +437,8 @@ bool ThermalHelper::readTemperature(
return true;
}
-bool ThermalHelper::readTemperatureThreshold(std::string_view sensor_name,
- TemperatureThreshold *out) const {
+bool ThermalHelperImpl::readTemperatureThreshold(std::string_view sensor_name,
+ TemperatureThreshold *out) const {
// Read the file. If the file can't be read temp will be empty string.
std::string temp;
std::string path;
@@ -458,7 +459,7 @@ bool ThermalHelper::readTemperatureThreshold(std::string_view sensor_name,
return true;
}
-void ThermalHelper::updateCoolingDevices(const std::vector<std::string> &updated_cdev) {
+void ThermalHelperImpl::updateCoolingDevices(const std::vector<std::string> &updated_cdev) {
int max_state;
for (const auto &target_cdev : updated_cdev) {
@@ -474,7 +475,7 @@ void ThermalHelper::updateCoolingDevices(const std::vector<std::string> &updated
}
}
-std::pair<ThrottlingSeverity, ThrottlingSeverity> ThermalHelper::getSeverityFromThresholds(
+std::pair<ThrottlingSeverity, ThrottlingSeverity> ThermalHelperImpl::getSeverityFromThresholds(
const ThrottlingArray &hot_thresholds, const ThrottlingArray &cold_thresholds,
const ThrottlingArray &hot_hysteresis, const ThrottlingArray &cold_hysteresis,
ThrottlingSeverity prev_hot_severity, ThrottlingSeverity prev_cold_severity,
@@ -515,8 +516,8 @@ std::pair<ThrottlingSeverity, ThrottlingSeverity> ThermalHelper::getSeverityFrom
return std::make_pair(ret_hot, ret_cold);
}
-bool ThermalHelper::isSubSensorValid(std::string_view sensor_data,
- const SensorFusionType sensor_fusion_type) {
+bool ThermalHelperImpl::isSubSensorValid(std::string_view sensor_data,
+ const SensorFusionType sensor_fusion_type) {
switch (sensor_fusion_type) {
case SensorFusionType::SENSOR:
if (!sensor_info_map_.count(sensor_data.data())) {
@@ -536,7 +537,7 @@ bool ThermalHelper::isSubSensorValid(std::string_view sensor_data,
return true;
}
-void ThermalHelper::clearAllThrottling(void) {
+void ThermalHelperImpl::clearAllThrottling(void) {
// Clear the CDEV request
for (const auto &cdev_info_pair : cooling_device_info_map_) {
cooling_devices_.writeCdevFile(cdev_info_pair.first, "0");
@@ -566,7 +567,7 @@ void ThermalHelper::clearAllThrottling(void) {
}
}
-bool ThermalHelper::initializeSensorMap(
+bool ThermalHelperImpl::initializeSensorMap(
const std::unordered_map<std::string, std::string> &path_map) {
for (const auto &sensor_info_pair : sensor_info_map_) {
std::string_view sensor_name = sensor_info_pair.first;
@@ -594,7 +595,7 @@ bool ThermalHelper::initializeSensorMap(
return true;
}
-bool ThermalHelper::initializeCoolingDevices(
+bool ThermalHelperImpl::initializeCoolingDevices(
const std::unordered_map<std::string, std::string> &path_map) {
for (auto &cooling_device_info_pair : cooling_device_info_map_) {
std::string cooling_device_name = cooling_device_info_pair.first;
@@ -682,14 +683,14 @@ bool ThermalHelper::initializeCoolingDevices(
return true;
}
-void ThermalHelper::setMinTimeout(SensorInfo *sensor_info) {
+void ThermalHelperImpl::setMinTimeout(SensorInfo *sensor_info) {
sensor_info->polling_delay = kMinPollIntervalMs;
sensor_info->passive_delay = kMinPollIntervalMs;
}
-void ThermalHelper::initializeTrip(const std::unordered_map<std::string, std::string> &path_map,
- std::set<std::string> *monitored_sensors,
- bool thermal_genl_enabled) {
+void ThermalHelperImpl::initializeTrip(const std::unordered_map<std::string, std::string> &path_map,
+ std::set<std::string> *monitored_sensors,
+ bool thermal_genl_enabled) {
for (auto &sensor_info : sensor_info_map_) {
if (!sensor_info.second.is_watch || (sensor_info.second.virtual_sensor_info != nullptr)) {
continue;
@@ -762,9 +763,9 @@ void ThermalHelper::initializeTrip(const std::unordered_map<std::string, std::st
}
}
-bool ThermalHelper::fillCurrentTemperatures(bool filterType, bool filterCallback,
- TemperatureType type,
- std::vector<Temperature> *temperatures) {
+bool ThermalHelperImpl::fillCurrentTemperatures(bool filterType, bool filterCallback,
+ TemperatureType type,
+ std::vector<Temperature> *temperatures) {
std::vector<Temperature> ret;
for (const auto &name_info_pair : sensor_info_map_) {
Temperature temp;
@@ -788,8 +789,9 @@ bool ThermalHelper::fillCurrentTemperatures(bool filterType, bool filterCallback
return ret.size() > 0;
}
-bool ThermalHelper::fillTemperatureThresholds(bool filterType, TemperatureType type,
- std::vector<TemperatureThreshold> *thresholds) const {
+bool ThermalHelperImpl::fillTemperatureThresholds(
+ bool filterType, TemperatureType type,
+ std::vector<TemperatureThreshold> *thresholds) const {
std::vector<TemperatureThreshold> ret;
for (const auto &name_info_pair : sensor_info_map_) {
TemperatureThreshold temp;
@@ -811,8 +813,8 @@ bool ThermalHelper::fillTemperatureThresholds(bool filterType, TemperatureType t
return ret.size() > 0;
}
-bool ThermalHelper::fillCurrentCoolingDevices(bool filterType, CoolingType type,
- std::vector<CoolingDevice> *cooling_devices) const {
+bool ThermalHelperImpl::fillCurrentCoolingDevices(
+ bool filterType, CoolingType type, std::vector<CoolingDevice> *cooling_devices) const {
std::vector<CoolingDevice> ret;
for (const auto &name_info_pair : cooling_device_info_map_) {
CoolingDevice value;
@@ -830,9 +832,9 @@ bool ThermalHelper::fillCurrentCoolingDevices(bool filterType, CoolingType type,
return ret.size() > 0;
}
-bool ThermalHelper::readDataByType(std::string_view sensor_data, float *reading_value,
- const SensorFusionType type, const bool force_no_cache,
- std::map<std::string, float> *sensor_log_map) {
+bool ThermalHelperImpl::readDataByType(std::string_view sensor_data, float *reading_value,
+ const SensorFusionType type, const bool force_no_cache,
+ std::map<std::string, float> *sensor_log_map) {
switch (type) {
case SensorFusionType::SENSOR:
if (!readThermalSensor(sensor_data.data(), reading_value, force_no_cache,
@@ -860,9 +862,9 @@ bool ThermalHelper::readDataByType(std::string_view sensor_data, float *reading_
constexpr int kTranTimeoutParam = 2;
-bool ThermalHelper::readThermalSensor(std::string_view sensor_name, float *temp,
- const bool force_no_cache,
- std::map<std::string, float> *sensor_log_map) {
+bool ThermalHelperImpl::readThermalSensor(std::string_view sensor_name, float *temp,
+ const bool force_no_cache,
+ std::map<std::string, float> *sensor_log_map) {
float temp_val = 0.0;
std::string file_reading;
boot_clock::time_point now = boot_clock::now();
@@ -982,7 +984,7 @@ bool ThermalHelper::readThermalSensor(std::string_view sensor_name, float *temp,
// This is called in the different thread context and will update sensor_status
// uevent_sensors is the set of sensors which trigger uevent from thermal core driver.
-std::chrono::milliseconds ThermalHelper::thermalWatcherCallbackFunc(
+std::chrono::milliseconds ThermalHelperImpl::thermalWatcherCallbackFunc(
const std::set<std::string> &uevent_sensors) {
std::vector<Temperature> temps;
std::vector<std::string> cooling_devices_to_update;
@@ -1160,11 +1162,11 @@ std::chrono::milliseconds ThermalHelper::thermalWatcherCallbackFunc(
return min_sleep_ms;
}
-bool ThermalHelper::connectToPowerHal() {
+bool ThermalHelperImpl::connectToPowerHal() {
return power_hal_service_.connect();
}
-void ThermalHelper::updateSupportedPowerHints() {
+void ThermalHelperImpl::updateSupportedPowerHints() {
for (auto const &name_status_pair : sensor_info_map_) {
if (!(name_status_pair.second.send_powerhint)) {
continue;
@@ -1190,7 +1192,7 @@ void ThermalHelper::updateSupportedPowerHints() {
}
}
-void ThermalHelper::sendPowerExtHint(const Temperature &t) {
+void ThermalHelperImpl::sendPowerExtHint(const Temperature &t) {
ATRACE_CALL();
std::lock_guard<std::shared_mutex> lock(sensor_status_map_mutex_);
ThrottlingSeverity prev_hint_severity;
diff --git a/thermal/thermal-helper.h b/thermal/thermal-helper.h
index 9480ffbd..a1873e70 100644
--- a/thermal/thermal-helper.h
+++ b/thermal/thermal-helper.h
@@ -73,77 +73,114 @@ struct SensorStatus {
class ThermalHelper {
public:
- explicit ThermalHelper(const NotificationCallback &cb);
- ~ThermalHelper() = default;
+ virtual ~ThermalHelper() = default;
+ virtual bool fillCurrentTemperatures(bool filterType, bool filterCallback, TemperatureType type,
+ std::vector<Temperature> *temperatures) = 0;
+ virtual bool fillTemperatureThresholds(bool filterType, TemperatureType type,
+ std::vector<TemperatureThreshold> *thresholds) const = 0;
+ virtual bool fillCurrentCoolingDevices(bool filterType, CoolingType type,
+ std::vector<CoolingDevice> *coolingdevices) const = 0;
+ virtual bool emulTemp(std::string_view target_sensor, const float temp) = 0;
+ virtual bool emulSeverity(std::string_view target_sensor, const int severity) = 0;
+ virtual bool emulClear(std::string_view target_sensor) = 0;
+ virtual bool isInitializedOk() const = 0;
+ virtual bool readTemperature(
+ std::string_view sensor_name, Temperature *out,
+ std::pair<ThrottlingSeverity, ThrottlingSeverity> *throtting_status = nullptr,
+ const bool force_sysfs = false) = 0;
+ virtual bool readTemperatureThreshold(std::string_view sensor_name,
+ TemperatureThreshold *out) const = 0;
+ virtual bool readCoolingDevice(std::string_view cooling_device, CoolingDevice *out) const = 0;
+ virtual const std::unordered_map<std::string, SensorInfo> &GetSensorInfoMap() const = 0;
+ virtual const std::unordered_map<std::string, CdevInfo> &GetCdevInfoMap() const = 0;
+ virtual const std::unordered_map<std::string, SensorStatus> &GetSensorStatusMap() const = 0;
+ virtual const std::unordered_map<std::string, ThermalThrottlingStatus> &
+ GetThermalThrottlingStatusMap() const = 0;
+ virtual const std::unordered_map<std::string, PowerRailInfo> &GetPowerRailInfoMap() const = 0;
+ virtual const std::unordered_map<std::string, PowerStatus> &GetPowerStatusMap() const = 0;
+ virtual const std::unordered_map<std::string, SensorTempStats> GetSensorTempStatsSnapshot() = 0;
+ virtual const std::unordered_map<std::string,
+ std::unordered_map<std::string, ThermalStats<int>>>
+ GetSensorCoolingDeviceRequestStatsSnapshot() = 0;
+ virtual void sendPowerExtHint(const Temperature &t) = 0;
+ virtual bool isAidlPowerHalExist() = 0;
+ virtual bool isPowerHalConnected() = 0;
+ virtual bool isPowerHalExtConnected() = 0;
+};
+
+class ThermalHelperImpl : public ThermalHelper {
+ public:
+ explicit ThermalHelperImpl(const NotificationCallback &cb);
+ ~ThermalHelperImpl() override = default;
bool fillCurrentTemperatures(bool filterType, bool filterCallback, TemperatureType type,
- std::vector<Temperature> *temperatures);
+ std::vector<Temperature> *temperatures) override;
bool fillTemperatureThresholds(bool filterType, TemperatureType type,
- std::vector<TemperatureThreshold> *thresholds) const;
+ std::vector<TemperatureThreshold> *thresholds) const override;
bool fillCurrentCoolingDevices(bool filterType, CoolingType type,
- std::vector<CoolingDevice> *coolingdevices) const;
- bool emulTemp(std::string_view target_sensor, const float temp);
- bool emulSeverity(std::string_view target_sensor, const int severity);
- bool emulClear(std::string_view target_sensor);
+ std::vector<CoolingDevice> *coolingdevices) const override;
+ bool emulTemp(std::string_view target_sensor, const float temp) override;
+ bool emulSeverity(std::string_view target_sensor, const int severity) override;
+ bool emulClear(std::string_view target_sensor) override;
// Disallow copy and assign.
- ThermalHelper(const ThermalHelper &) = delete;
- void operator=(const ThermalHelper &) = delete;
+ ThermalHelperImpl(const ThermalHelperImpl &) = delete;
+ void operator=(const ThermalHelperImpl &) = delete;
- bool isInitializedOk() const { return is_initialized_; }
+ bool isInitializedOk() const override { return is_initialized_; }
// Read the temperature of a single sensor.
- bool readTemperature(std::string_view sensor_name, Temperature *out);
bool readTemperature(
std::string_view sensor_name, Temperature *out,
std::pair<ThrottlingSeverity, ThrottlingSeverity> *throtting_status = nullptr,
- const bool force_sysfs = false);
+ const bool force_sysfs = false) override;
- bool readTemperatureThreshold(std::string_view sensor_name, TemperatureThreshold *out) const;
+ bool readTemperatureThreshold(std::string_view sensor_name,
+ TemperatureThreshold *out) const override;
// Read the value of a single cooling device.
- bool readCoolingDevice(std::string_view cooling_device, CoolingDevice *out) const;
+ bool readCoolingDevice(std::string_view cooling_device, CoolingDevice *out) const override;
// Get SensorInfo Map
- const std::unordered_map<std::string, SensorInfo> &GetSensorInfoMap() const {
+ const std::unordered_map<std::string, SensorInfo> &GetSensorInfoMap() const override {
return sensor_info_map_;
}
// Get CdevInfo Map
- const std::unordered_map<std::string, CdevInfo> &GetCdevInfoMap() const {
+ const std::unordered_map<std::string, CdevInfo> &GetCdevInfoMap() const override {
return cooling_device_info_map_;
}
// Get SensorStatus Map
- const std::unordered_map<std::string, SensorStatus> &GetSensorStatusMap() const {
+ const std::unordered_map<std::string, SensorStatus> &GetSensorStatusMap() const override {
std::shared_lock<std::shared_mutex> _lock(sensor_status_map_mutex_);
return sensor_status_map_;
}
// Get ThermalThrottling Map
const std::unordered_map<std::string, ThermalThrottlingStatus> &GetThermalThrottlingStatusMap()
- const {
+ const override {
return thermal_throttling_.GetThermalThrottlingStatusMap();
}
// Get PowerRailInfo Map
- const std::unordered_map<std::string, PowerRailInfo> &GetPowerRailInfoMap() const {
+ const std::unordered_map<std::string, PowerRailInfo> &GetPowerRailInfoMap() const override {
return power_files_.GetPowerRailInfoMap();
}
// Get PowerStatus Map
- const std::unordered_map<std::string, PowerStatus> &GetPowerStatusMap() const {
+ const std::unordered_map<std::string, PowerStatus> &GetPowerStatusMap() const override {
return power_files_.GetPowerStatusMap();
}
// Get Thermal Stats Sensor Map
- const std::unordered_map<std::string, SensorTempStats> GetSensorTempStatsSnapshot() {
+ const std::unordered_map<std::string, SensorTempStats> GetSensorTempStatsSnapshot() override {
return thermal_stats_helper_.GetSensorTempStatsSnapshot();
}
// Get Thermal Stats Sensor, Binded Cdev State Request Map
const std::unordered_map<std::string, std::unordered_map<std::string, ThermalStats<int>>>
- GetSensorCoolingDeviceRequestStatsSnapshot() {
+ GetSensorCoolingDeviceRequestStatsSnapshot() override {
return thermal_stats_helper_.GetSensorCoolingDeviceRequestStatsSnapshot();
}
- void sendPowerExtHint(const Temperature &t);
- bool isAidlPowerHalExist() { return power_hal_service_.isAidlPowerHalExist(); }
- bool isPowerHalConnected() { return power_hal_service_.isPowerHalConnected(); }
- bool isPowerHalExtConnected() { return power_hal_service_.isPowerHalExtConnected(); }
+ void sendPowerExtHint(const Temperature &t) override;
+ bool isAidlPowerHalExist() override { return power_hal_service_.isAidlPowerHalExist(); }
+ bool isPowerHalConnected() override { return power_hal_service_.isPowerHalConnected(); }
+ bool isPowerHalExtConnected() override { return power_hal_service_.isPowerHalExtConnected(); }
private:
bool initializeSensorMap(const std::unordered_map<std::string, std::string> &path_map);