Rick Ai
Rick Ai

Reputation: 381

Rooted android device throw EACCES: permission denied exception when I try to get CPU's temperature

I was try to get the android devices' CPU temperature, and after a little search I found some files store the data of temperature, the only thing I need is to read those files. Most specifically, I found most device contain temperature in the path "/sys/class/thermal/thermal_zone1/temp".

I have added permission in my manifest file.

however, I found in some devices the app is running fine (4.1, 4.4, 5.1 version), in 2 extra devices, it does not work, I printed the log, it shows EACCES: permission denied

I found both those two devices have been rooted before. I used adb shell with su command and those file really exist and contain the temperature data.

Upvotes: 2

Views: 502

Answers (1)

Plop
Plop

Reputation: 21

It probably failed on selinux enforced device (i.e. device running android 5.0 and later).

You will need a custom rom, with special policies to access those file from your app, or call

adb shell setenforce 0

to disable until next boot (on rooted phone only)

Upvotes: 2

Related Questions