From 93a2d68efeba7d12700b4e64fa0b79068c2529f3 Mon Sep 17 00:00:00 2001 From: Polina Bondarenko Date: Thu, 19 Jan 2017 15:55:19 +0100 Subject: [PATCH] thermal: substitute undefined temperature by NAN. Bug: 34107726 Test: vts, cts Change-Id: Ia6e9e83691e8b6b5e2760579e1131a5994a48572 --- thermal/1.0/default/Thermal.cpp | 18 ++++++++++++++---- thermal/1.0/types.hal | 13 ++++--------- .../vts/functional/thermal_hidl_hal_test.cpp | 13 ++++--------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/thermal/1.0/default/Thermal.cpp b/thermal/1.0/default/Thermal.cpp index 8a8ad0a423..2dd00905e1 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 +#include #include @@ -33,6 +34,14 @@ namespace thermal { 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 @@ Return Thermal::getTemperatures(getTemperatures_cb _hidl_cb) { ; } 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 8864f43328..eb5d7c78a7 100644 --- a/thermal/1.0/types.hal +++ b/thermal/1.0/types.hal @@ -45,28 +45,27 @@ struct Temperature { 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 @@ struct ThermalStatus { */ 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 8a5ea2c988..d922169182 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 @@ using ::android::sp; #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 @@ class ThermalHidlTest : public ::testing::Test { // .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.