Sensor Type TYPE_TEMPERATURE has been deprecated [since Android 2.3] probably which was giving info about CPU temperature. Now we have Sensor Type TYPE_AMBIENT_TEMPERATURE which will provide us room temperature (none of my use, & btw not all devices&/Android versions support it)
I checked few apps which measures CPU temperature. Probably they're reading system files. I tried locating, in some devices I'm able to locate it inside following path:
sys/devices/virtual/thermal/thermal_zone0/temp
The structure bit varies from vendor to vendor & also the unit of measurement. fine! But in many devices I'm simply unable to locate any such files & in same devices those apps work! I wonder, how!
How can we measure CPU temperature in Android?
Xamarin.Android sample is here - it's as straight forward as looping through a list of predefined file paths (23 in my case) and reading a line from the first file which do not fail upon opening (and then converting the string to a number, scaling it to degrees).
Verified it on the following devices:
Not working:
Context
Programs such as CPU-Z have internal list of paths which can be probed for files that contain the name of the sensor/reading (typically named "type" or "name") and actual value (typically named "temp"). E.g. under /sys/devices/virtual/thermal/thermal_zone0
one might read "cpu-0-0-user" value from type
file and "32100" value from temp
file.
There're multiple files with different sensor names at a single device. One might guess by the name of the sensor if it related to CPU or not (containing CPU or SoC or smth else in the name). Precisely speaking there's no such thing as single "CPU temperature" value, there are many. If you don't care about the specifics (e.g. telling the difference between core or package temperature) picking one value should be representative of CPU thermal situation.
Also sensor names (as well as file paths) would be different for various device vendors. Sensor values can be in thousands as integers or not. The variety of the ways temp reading can be implemented prompts why there's no standard API in Android for CPU temp.
The list I gathered is not full (and seems it is smaller than the one inside CPU-Z) though I did spend quite some time googling.
How do I find the right paths for a specific device
cd
, ls
and cat
going through various paths (starting with the list in the sample above) investigating what's inside and searching for the sensor of interest If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With