0

Thermal values through adb

I am trying to get thermal values of my device programatically. I am able to do it in adb but unable to do this programatically. How can I loop over each and every directory in the directory "thermal" to get the particular value. Some part of my code is as following :

Process p=Runtime.getRuntime().exec("cd sys/class/thermal/");
Mrudul Tora
  • 715
  • 8
  • 14

2 Answers2

0

You cannot access /sys/class/thermal/ through an app because the user performing the action (something like u0_aXYZ) does not have enough permission to perform this action compared to a (root) adb shell.

You can do for instance:

adb shell
run-as your-app-package-name

and from now on you can navigate across the device file system and take a look at the folders your app can access.

If you want to proceed with that your only option is to have a rooted device and build an app with root permissions.

Lino
  • 5,084
  • 3
  • 21
  • 39
0

Now I found to do this programatically. I used for loop to find the values. Visit the detailed answer here.

    for(int i=0;i<29;i++){
            float temp;
            Process process = Runtime.getRuntime().exec("cat sys/class/thermal/thermal_zone" + i + "/temp");
            process.waitFor();
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line = reader.readLine();
            if (line != null) {
                temp = Float.parseFloat(line);
            }
            reader.close();
            process.destroy();
}
Mrudul Tora
  • 715
  • 8
  • 14