thermal: substitute undefined temperature by NAN.
Bug: 34107726
Test: vts, cts
Change-Id: Ia6e9e83691e8b6b5e2760579e1131a5994a48572
diff --git a/thermal/1.0/default/Thermal.cpp b/thermal/1.0/default/Thermal.cpp
index 8a8ad0a..2dd0090 100644
--- a/thermal/1.0/default/Thermal.cpp
+++ b/thermal/1.0/default/Thermal.cpp
@@ -17,6 +17,7 @@
#define LOG_TAG "android.hardware.thermal@1.0-impl"
#include <errno.h>
+#include <math.h>
#include <vector>
@@ -33,6 +34,14 @@
namespace V1_0 {
namespace implementation {
+namespace {
+
+float finalizeTemperature(float temperature) {
+ return temperature == UNKNOWN_TEMPERATURE ? NAN : temperature;
+}
+
+}
+
Thermal::Thermal(thermal_module_t* module) : mModule(module) {}
// Methods from ::android::hardware::thermal::V1_0::IThermal follow.
@@ -76,10 +85,11 @@
;
}
temperatures[i].name = list[i].name;
- temperatures[i].currentValue = list[i].current_value;
- temperatures[i].throttlingThreshold = list[i].throttling_threshold;
- temperatures[i].shutdownThreshold = list[i].shutdown_threshold;
- temperatures[i].vrThrottlingThreshold = list[i].vr_throttling_threshold;
+ temperatures[i].currentValue = finalizeTemperature(list[i].current_value);
+ temperatures[i].throttlingThreshold = finalizeTemperature(list[i].throttling_threshold);
+ temperatures[i].shutdownThreshold = finalizeTemperature(list[i].shutdown_threshold);
+ temperatures[i].vrThrottlingThreshold =
+ finalizeTemperature(list[i].vr_throttling_threshold);
}
}
}
diff --git a/thermal/1.0/types.hal b/thermal/1.0/types.hal
index 8864f43..eb5d7c7 100644
--- a/thermal/1.0/types.hal
+++ b/thermal/1.0/types.hal
@@ -45,28 +45,27 @@
string name;
/**
- * Current temperature in Celsius. If not available set by HAL to
- * UNKNOWN_TEMPERATURE.
+ * Current temperature in Celsius. If not available set by HAL to NAN.
* Current temperature can be in any units if type=UNKNOWN.
*/
float currentValue;
/**
* Throttling temperature constant for this temperature.
- * If not available, set by HAL to UNKNOWN_TEMPERATURE.
+ * If not available, set by HAL to NAN.
*/
float throttlingThreshold;
/**
* Shutdown temperature constant for this temperature.
- * If not available, set by HAL to UNKNOWN_TEMPERATURE.
+ * If not available, set by HAL to NAN.
*/
float shutdownThreshold;
/**
* Threshold temperature above which the VR mode clockrate minimums cannot
* be maintained for this device.
- * If not available, set by HAL to UNKNOWN_TEMPERATURE.
+ * If not available, set by HAL to NAN.
*/
float vrThrottlingThreshold;
@@ -135,7 +134,3 @@
*/
string debugMessage;
};
-
-/**
- * TODO(pbond): add float constant UNDEFINED_TEMPERATURE.
- */
diff --git a/thermal/1.0/vts/functional/thermal_hidl_hal_test.cpp b/thermal/1.0/vts/functional/thermal_hidl_hal_test.cpp
index 8a5ea2c..d922169 100644
--- a/thermal/1.0/vts/functional/thermal_hidl_hal_test.cpp
+++ b/thermal/1.0/vts/functional/thermal_hidl_hal_test.cpp
@@ -43,8 +43,6 @@
#define THERMAL_SERVICE_NAME "thermal"
#define MONITORING_OPERATION_NUMBER 10
-#define UNDEFINED_TEMPERATURE (-FLT_MAX)
-
#define MAX_DEVICE_TEMPERATURE 200
#define MAX_FAN_SPEED 20000
@@ -127,21 +125,18 @@
// .currentValue of known type is in Celsius and must be reasonable.
EXPECT_TRUE(temperature.type == TemperatureType::UNKNOWN ||
std::abs(temperature.currentValue) < MAX_DEVICE_TEMPERATURE ||
- temperature.currentValue == UNDEFINED_TEMPERATURE);
+ isnan(temperature.currentValue));
// .name must not be empty.
EXPECT_LT(0u, temperature.name.size());
// .currentValue must not exceed .shutdwonThreshold if defined.
EXPECT_TRUE(temperature.currentValue < temperature.shutdownThreshold ||
- temperature.currentValue == UNDEFINED_TEMPERATURE ||
- temperature.shutdownThreshold == UNDEFINED_TEMPERATURE);
+ isnan(temperature.currentValue) || isnan(temperature.shutdownThreshold));
// .throttlingThreshold must not exceed .shutdownThreshold if defined.
- EXPECT_TRUE(temperature.throttlingThreshold <
- temperature.shutdownThreshold ||
- temperature.throttlingThreshold == UNDEFINED_TEMPERATURE ||
- temperature.shutdownThreshold == UNDEFINED_TEMPERATURE);
+ EXPECT_TRUE(temperature.throttlingThreshold < temperature.shutdownThreshold ||
+ isnan(temperature.throttlingThreshold) || isnan(temperature.shutdownThreshold));
}
// Check validity of CPU usage returned by Thermal HAL.