Android 如何獲取CPU的溫度


最近的項目有需求要獲取CPU的溫度,在網上找了一些資料,基本算是解決了問題:

進入adb shell執行下面的命令:

shell@android:/ $ cat /etc/thermald.conf 

這個不同設備得到的結果可能是不已樣的,有這樣的:

sampling         5000

[tsens_tz_sensor0]
sampling         5000
thresholds       10
thresholds_clr   5
actions          none
action_info      0

[tsens_tz_sensor1]
sampling         5000
thresholds       60
thresholds_clr   57
actions          none
action_info      0

[tsens_tz_sensor2]
sampling         5000
thresholds       60
thresholds_clr   57
actions          none
action_info      0

[tsens_tz_sensor3]
sampling         5000
thresholds       60
thresholds_clr   57
actions          none
action_info      0

[tsens_tz_sensor4]
sampling         5000
thresholds       60
thresholds_clr   57
actions          none
action_info      0

[tsens_tz_sensor5]
sampling         5000
thresholds       60
thresholds_clr   57
actions          none
action_info      0

[tsens_tz_sensor6]
sampling         5000
thresholds       60
thresholds_clr   57
actions          none
action_info      0

[tsens_tz_sensor7]
sampling         1500
thresholds       95     120
thresholds_clr   87     115
actions          cpu    cpu+shutdown
action_info      384000 384000+5000

[tsens_tz_sensor8]
sampling         1500
thresholds       95     120
thresholds_clr   87     115
actions          cpu    cpu+shutdown
action_info      384000 384000+5000

[tsens_tz_sensor9]
sampling         1500
thresholds       95     120
thresholds_clr   87     115
actions          cpu    cpu+shutdown
action_info      384000 384000+5000

[tsens_tz_sensor10]
sampling         1500
thresholds       95     120
thresholds_clr   87     115
actions          cpu    cpu+shutdown
action_info      384000 384000+5000

[batt_therm]
sampling         1500
thresholds       410             420             430             440             450
thresholds_clr   400             410             420             430             440
actions          cpu+lcd+battery cpu+lcd+battery cpu+lcd+battery cpu+lcd+battery cpu+lcd+battery
action_info      1350000+192+0   1134000+181+1   1026000+181+1   918000+171+2    810000+171+3

這樣的:

sampling         5000

[tsens_tz_sensor0]
sampling         1000
thresholds       60      90      95      100     105     110     115     120
thresholds_clr   57      85      90      95      100     105     110     115
actions          cpu     cpu     cpu     cpu     cpu     cpu     cpu     shutdown
action_info      1512000 1188000 918000  756000  648000  540000  486000  5000

[tsens_tz_sensor1]
sampling         1000
thresholds       60      90      95      100     105     110     115     120
thresholds_clr   57      85      90      95      100     105     110     115
actions          cpu     cpu     cpu     cpu     cpu     cpu     cpu     shutdown
action_info      1512000 1188000 918000  756000  648000  540000  486000  5000

[tsens_tz_sensor2]
sampling         1000
thresholds       60      90      95      100     105     110     115     120
thresholds_clr   57      85      90      95      100     105     110     115
actions          cpu     cpu     cpu     cpu     cpu     cpu     cpu     shutdown
action_info      1512000 1188000 918000  756000  648000  540000  486000  5000

[tsens_tz_sensor3]
sampling         1000
thresholds       60      90      95      100     105     110     115     120
thresholds_clr   57      85      90      95      100     105     110     115
actions          cpu     cpu     cpu     cpu     cpu     cpu     cpu     shutdown
action_info      1512000 1188000 918000  756000  648000  540000  486000  5000

[tsens_tz_sensor4]
sampling         1000
thresholds       60      90      95      100     105     110     115     120
thresholds_clr   57      85      90      95      100     105     110     115
actions          cpu     cpu     cpu     cpu     cpu     cpu     cpu     shutdown
action_info      1512000 1188000 918000  756000  648000  540000  486000  5000

[tsens_tz_sensor5]
sampling         1000
thresholds       60      90      95      100     105     110     115     120
thresholds_clr   57      85      90      95      100     105     110     115
actions          cpu     cpu     cpu     cpu     cpu     cpu     cpu     shutdown
action_info      1512000 1188000 918000  756000  648000  540000  486000  5000

[tsens_tz_sensor6]
sampling         1000
thresholds       60      90      95      100     105     110     115     120
thresholds_clr   57      85      90      95      100     105     110     115
actions          cpu     cpu     cpu     cpu     cpu     cpu     cpu     shutdown
action_info      1512000 1188000 918000  756000  648000  540000  486000  5000

[tsens_tz_sensor7]
sampling         1000
thresholds       60      90      95      100     105     110     115     120
thresholds_clr   57      85      90      95      100     105     110     115
actions          cpu     cpu     cpu     cpu     cpu     cpu     cpu     shutdown
action_info      1512000 1188000 918000  756000  648000  540000  486000  5000

[tsens_tz_sensor8]
sampling         1000
thresholds       60      90      95      100     105     110     115     120
thresholds_clr   57      85      90      95      100     105     110     115
actions          cpu     cpu     cpu     cpu     cpu     cpu     cpu     shutdown
action_info      1512000 1188000 918000  756000  648000  540000  486000  5000

[tsens_tz_sensor9]
sampling         1000
thresholds       60      90      95      100     105     110     115     120
thresholds_clr   57      85      90      95      100     105     110     115
actions          cpu     cpu     cpu     cpu     cpu     cpu     cpu     shutdown
action_info      1512000 1188000 918000  756000  648000  540000  486000  5000

[tsens_tz_sensor10]
sampling         1000
thresholds       60      90      95      100     105     110     115     120
thresholds_clr   57      85      90      95      100     105     110     115
actions          cpu     cpu     cpu     cpu     cpu     cpu     cpu     shutdown
action_info      1512000 1188000 918000  756000  648000  540000  486000  5000

還有壓根就不能執行的情況。

 

個人理解,這個就是對應不同設備的溫度傳感器。

然后,我們可以看到,有的傳感器是針對CPU的。那么到下面的目錄:

shell@android:/sys/class/thermal $

你可以找到這些傳感器,然后進入對應的傳感器,用cat指令可以知道溫度了。

shell@android:/sys/class/thermal/thermal_zone7 $ cat temp

## cat type 的話應該可以獲取傳感器的類型信息。

 

雖然解決了問題,但是不是很理解。比如,這個是linux系統的通用設置嗎? 其他傳感器都對應了什么? 等等。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM