Accessing temperature sensors on Android (6+) platforms

856 views
Skip to first unread message

Guru Prasad

unread,
Oct 11, 2017, 3:32:40 PM10/11/17
to android-platform
I'm a researcher looking into studying temperature on smartphones. My work requires me to track CPU temperature on Android devices.

I've observed that on newer versions of Android, access to /sys/class/thermal seems to be denied to my app with a message on these lines:
avc: denied { search } for name="thermal" dev="sysfs" ino=17530 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:sysfs_thermal:s0 tclass=dir permissive=0

I understand that this is a SELinux message telling me that my (untrusted) app has been denied access to a file of type sysfs_thermal.

So far, I have tried the following with no luck:
  • Attempt to read file via a simple cat-like binary packed along with the app
  • Attempt to read file via Runtime.getRuntime().exec("cat ...")
  • Attempt to read file via Java APIs (tried both File and RandomAccessFile)
What I find confusing is that other apps such as CPU-Z are able to read various temperature sensors under /sys/class/thermal without difficulty.

For the record, I'm using a Nexus 6P running stock Android 6.0.1 kernel version: 3.10.73-g8c0675f.

How can I read temperature sensor values on these devices and/or android versions?

Braganza Roberts

unread,
Oct 12, 2017, 2:46:16 AM10/12/17
to android-...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-platform+unsubscribe@googlegroups.com.
To post to this group, send email to android-platform@googlegroups.com.
Visit this group at https://groups.google.com/group/android-platform.
For more options, visit https://groups.google.com/d/optout.

Paul Chang

unread,
Nov 7, 2017, 11:02:27 AM11/7/17
to android-...@googlegroups.com
You should read this node directly,not accessing to the /sys/class/thermal dir:
/sys/class/thermal/thermal_zone0/temp
Reply all
Reply to author
Forward
0 new messages