基本概念
參閱下面兩篇文章,就可以大概瞭解一些概念的內容了
https://source.android.com/devices/architecture/hidl/thermal-mitigation
https://blog.csdn.net/feelabclihu/article/details/107873407
功能實現
這裡我們不做講解,直接給參考例子,基本拿來可以用
》Thermal HAL 2.0的實現
https://github.com/LineageOS/android_hardware_google_pixel/tree/lineage-18.1/thermal
》sepolicy相關設定
https://github.com/LineageOS/android_hardware_google_pixel-sepolicy/tree/lineage-19.0/thermal
》thermal_info_config配置檔案,根據自身系統配置
https://github.com/LineageOS/android_device_google_taimen/blob/lineage-17.1/thermal_info_config.json
測試
技巧一:
執行 adb shell dumpsys thermalservice 可以檢視溫度的資訊,例如:
技巧二:
Linux kernel中有模擬溫度的方式,編核心時開啟選項開關CONFIG_THERMAL_EMULATION=y,這樣就會看到如下這個值:
/sys/class/thermal/thermal_zone0/emul_temp
之後測試可以:
echo 100000 > /sys/class/thermal/thermal_zone0/emul_temp
然後使用dumpsys thermalservice 檢視這個模擬的溫度值
VTS/CTS測試
幾個相關的測試項
run vts -m VtsHalThermalV2_0TargetTest
run vts -m VtsHalThermalV1_0TargetTest
run vts -m VtsHalThermalV1_1TargetTest
run cts -m CtsOsTestCases -t android.os.cts.PowerManager_ThermalTest
補充
/frameworks/base/services/core/java/com/android/server/power/ThermalManagerService.java
Android framework中有去註冊監聽器,檢測Thermal HAL 的回撥事件,高溫時可能出發shutdown
private void shutdownIfNeeded(Temperature temperature) {
if (temperature.getStatus() != Temperature.THROTTLING_SHUTDOWN) {
return;
}
final PowerManager powerManager = getContext().getSystemService(PowerManager.class);
switch (temperature.getType()) {
case Temperature.TYPE_CPU:
// Fall through
case Temperature.TYPE_GPU:
// Fall through
case Temperature.TYPE_NPU:
// Fall through
case Temperature.TYPE_SKIN:
powerManager.shutdown(false, PowerManager.SHUTDOWN_THERMAL_STATE, false);
break;
case Temperature.TYPE_BATTERY:
powerManager.shutdown(false, PowerManager.SHUTDOWN_BATTERY_THERMAL_STATE, false);
break;
}
}
關於溫度的幾個等級可以參考 https://source.android.com/devices/architecture/hidl/thermal-mitigation
觸發這些事件的溫度就是我們在thermal_info_config.json配置的, 如果不需要觸發回撥事件可以設定 "Monitor":false
"Sensors":[
{
"Name":"cpu-thermal",
"Type":"CPU",
"HotThreshold":[
"NAN",
"NAN",
"NAN",
95.0,
"NAN",
"NAN",
125.0
],
"VrThreshold":"NAN",
"Multiplier":0.001,
"Monitor":false
}
]