thermal-hal: Return failure only for uninitialized sensor request
The thermal hal checks for all configured sensors are initialized
or not. If any of the sensors in config is not initialized or failed
to initialize, it returns failure immediately for all sensors
temperature related HAL API request.
Change-Id: I3f06fa74262dcf22268d265725baee69520696aa
(cherry picked from commit 947b8a06cddc33c1fbc5e8408ef0ffb08a8f18b3)
Signed-off-by: Priyansh Jain <quic_priyjain@quicinc.com>
diff --git a/thermalUtilsNetlink.cpp b/thermalUtilsNetlink.cpp
index 7a6c86d..1a0e3a2 100644
--- a/thermalUtilsNetlink.cpp
+++ b/thermalUtilsNetlink.cpp
@@ -31,7 +31,7 @@
/* Changes from Qualcomm Innovation Center are provided under the following license:
-Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
+Copyright (c) 2023, 2025 Qualcomm Innovation Center, Inc. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause-Clear */
#include <android-base/file.h>
@@ -66,11 +66,9 @@
std::vector<struct therm_sensor> sensorList;
std::vector<struct target_therm_cfg> therm_cfg = cfg.fetchConfig();
- is_sensor_init = false;
is_cdev_init = false;
ret = cmnInst.initThermalZones(therm_cfg);
if (ret > 0) {
- is_sensor_init = true;
sensorList = cmnInst.fetch_sensor_list();
std::lock_guard<std::mutex> _lock(sens_cb_mutex);
for (struct therm_sensor sens: sensorList) {
@@ -88,6 +86,34 @@
}
}
+bool ThermalUtils::isSensorInitialized()
+{
+ std::lock_guard<std::mutex> _lock(sens_cb_mutex);
+
+ if (thermalConfig.begin() == thermalConfig.end())
+ return false;
+
+ return true;
+}
+
+bool ThermalUtils::isSensorInitialized(TemperatureType type)
+{
+ std::unordered_map<int, struct therm_sensor>::iterator it;
+ std::lock_guard<std::mutex> _lock(sens_cb_mutex);
+
+ if (thermalConfig.begin() == thermalConfig.end())
+ return false;
+
+ for (it = thermalConfig.begin(); it != thermalConfig.end();
+ it++) {
+ struct therm_sensor& sens = it->second;
+ if (sens.t.type == type)
+ return true;
+ }
+
+ return false;
+}
+
void ThermalUtils::Notify(struct therm_sensor& sens)
{
int severity = cmnInst.estimateSeverity(sens);
@@ -136,8 +162,9 @@
std::vector<struct target_therm_cfg>::iterator it_vec;
std::vector<std::string>::iterator it;
- if (isSensorInitialized())
+ if (thermalConfig.find(tzn) != thermalConfig.end())
return;
+
for (it_vec = therm_cfg.begin();
it_vec != therm_cfg.end(); it_vec++) {
for (it = it_vec->sensor_list.begin();
@@ -153,16 +180,18 @@
<< std::endl;
return;
}
- ret = cmnInst.initThermalZones(therm_cfg);
+ ret = cmnInst.initNewThermalZone(*it_vec);
if (ret > 0) {
- is_sensor_init = true;
sensorList = cmnInst.fetch_sensor_list();
std::lock_guard<std::mutex> _lock(sens_cb_mutex);
for (struct therm_sensor sens: sensorList) {
+ if (sens.sensor_name != name)
+ continue;
thermalConfig[sens.tzn] = sens;
cmnInst.read_temperature(sens);
cmnInst.estimateSeverity(sens);
cmnInst.initThreshold(sens);
+ break;
}
}
}