How do I get the CPU temperature?

后端 未结 5 1618
挽巷
挽巷 2020-12-10 04:39

I know it\'s somehow possible to get the CPU\'s temperature because I downloaded an app that does it in an unrooted device. How is it done?

edit: The application is

5条回答
  •  我在风中等你
    2020-12-10 05:11

    Here is a current set of paths that are used in production in Dec 2019 to find CPU temperature. There are so many different paths because different OEMs put the temperature in different places.

    These three locations are also used in addition to the one listed above:

    /sys/htc/cpu_temp
    /sys/devices/platform/tegra-i2c.3/i2c-4/4-004c/ext_temperature
    /sys/devices/platform/tegra-tsensor/tsensor_temperature
    

    The ones already listed as answer previously still hold true:

    /sys/devices/system/cpu/cpu0/cpufreq/cpu_temp
    /sys/devices/system/cpu/cpu0/cpufreq/FakeShmoo_cpu_temp
    /sys/class/thermal/thermal_zone1/temp
    /sys/class/i2c-adapter/i2c-4/4-004c/temperature
    /sys/devices/platform/tegra-i2c.3/i2c-4/4-004c/temperature
    /sys/devices/platform/omap/omap_temp_sensor.0/temperature
    /sys/devices/platform/tegra_tmon/temp1_input
    /sys/kernel/debug/tegra_thermal/temp_tj
    /sys/devices/platform/s5p-tmu/temperature
    /sys/class/thermal/thermal_zone0/temp
    /sys/devices/virtual/thermal/thermal_zone0/temp
    /sys/class/hwmon/hwmon0/device/temp1_input
    /sys/devices/virtual/thermal/thermal_zone1/temp
    /sys/devices/platform/s5p-tmu/curr_temp
    

    Here's a code snippet for how to read those system files. This is classic Unix philosophy 'everything is a file', even sensor readings in this case are accessed by reading a 'file'.

    RandomAccessFile reader = new RandomAccessFile("/sys/devices/system/cpu/cpu0/cpufreq/cpu_temp", "r");
    String line = reader.readLine();
    

    The result is most likely in milli Celsius, such as 33000 for 33 degree C, so you need to divide by 1000 to get temperature in C.

提交回复
热议问题