diff --git a/services/core/jni/com_android_server_HardwarePropertiesManagerService.cpp b/services/core/jni/com_android_server_HardwarePropertiesManagerService.cpp index 17a6c297bd8f8..545b3d757e103 100644 --- a/services/core/jni/com_android_server_HardwarePropertiesManagerService.cpp +++ b/services/core/jni/com_android_server_HardwarePropertiesManagerService.cpp @@ -19,6 +19,7 @@ #include "JNIHelp.h" #include "jni.h" +#include #include #include @@ -56,10 +57,16 @@ static struct { jmethodID initMethod; } gCpuUsageInfoClassInfo; +jfloat gUndefinedTemperature; + static sp gThermalModule; // ---------------------------------------------------------------------------- +float finalizeTemperature(float temperature) { + return isnan(temperature) ? gUndefinedTemperature : temperature; +} + static void nativeInit(JNIEnv* env, jobject obj) { // TODO(b/31632518) if (gThermalModule == nullptr) { @@ -128,16 +135,16 @@ static jfloatArray nativeGetDeviceTemperatures(JNIEnv *env, jclass /* clazz */, if (static_cast(list[i].type) == type) { switch (source) { case TEMPERATURE_CURRENT: - values[length++] = list[i].currentValue; + values[length++] = finalizeTemperature(list[i].currentValue); break; case TEMPERATURE_THROTTLING: - values[length++] = list[i].throttlingThreshold; + values[length++] = finalizeTemperature(list[i].throttlingThreshold); break; case TEMPERATURE_SHUTDOWN: - values[length++] = list[i].shutdownThreshold; + values[length++] = finalizeTemperature(list[i].shutdownThreshold); break; case TEMPERATURE_THROTTLING_BELOW_VR_MIN: - values[length++] = list[i].vrThrottlingThreshold; + values[length++] = finalizeTemperature(list[i].vrThrottlingThreshold); break; } } @@ -204,6 +211,12 @@ int register_android_server_HardwarePropertiesManagerService(JNIEnv* env) { gCpuUsageInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz); gCpuUsageInfoClassInfo.initMethod = GetMethodIDOrDie(env, gCpuUsageInfoClassInfo.clazz, "", "(JJ)V"); + + clazz = env->FindClass("android/os/HardwarePropertiesManager"); + jfieldID undefined_temperature_field = GetStaticFieldIDOrDie(env, clazz, + "UNDEFINED_TEMPERATURE", "F"); + gUndefinedTemperature = env->GetStaticFloatField(clazz, undefined_temperature_field); + return res; }