diff --git a/device.inc.php b/device.inc.php index 0bb0531..41b07d4 100644 --- a/device.inc.php +++ b/device.inc.php @@ -281,20 +281,48 @@ function device_cputop_async(string $atf_host, string $device) : Amp\Promise function device_temperature_async(string $atf_host, string $device) : Amp\Promise { return Amp\call(function() use($atf_host, $device) { - //NOTE: on current devices 16 thermal zone are responsible for GPU temperature probing - list($code, $lines) = yield host_exec_async($atf_host, "%{adb}% -s $device shell cat /sys/class/thermal/thermal_zone16/temp", DEPLOY_OPT_ERR_OK, 1); + list($code, $lines) = yield host_exec_async($atf_host, "%{adb}% -s $device shell dumpsys thermalservice", DEPLOY_OPT_ERR_OK, 1); if($code !== 0) - return 0; + return array(); - foreach($lines as $idx => $line) - { - $line = trim($line); - if(!$line) - continue; - return intval($line); - } - - return 0; + return device_parse_soc_temps($lines); }); } + +function device_parse_soc_temps($thermal_output_lines) +{ + $cpu_temp = null; + $gpu_temp = null; + + $hal_section_found = false; + + foreach($thermal_output_lines as $line) + { + if(!$hal_section_found) + { + if(strpos($line, 'Current temperatures from HAL:') !== false) + $hal_section_found = true; + continue; + } + + if(strpos($line, 'mType=0') !== false) //Type 0 indicates CPI + $cpu_temp = device_parse_thermal_line($line); + + if(strpos($line, 'mType=1') !== false) //Type 1 indicates GPU + $gpu_temp = device_parse_thermal_line($line); + + if($cpu_temp && $gpu_temp) + break; + } + + return [ + 'cpu_temp' => $cpu_temp, + 'gpu_temp' => $gpu_temp + ]; +} + +function device_parse_thermal_line($line) +{ + return preg_match('/mValue=([^,]+)/', $line, $matches) ? floatval($matches[1]) : null; +}