1# @ohos.thermal (热管理) 2 3<!--Kit: Basic Services Kit--> 4<!--Subsystem: PowerManager--> 5<!--Owner: @zhang-yinglie; @volcano_wang--> 6<!--Designer: @wangyantian0--> 7<!--Tester: @alien0208--> 8<!--Adviser: @w_Machine_cc--> 9 10该模块提供热管理相关的接口,包括热档位查询及注册回调等功能。 11 12> **说明:** 13> 14> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 15 16## 导入模块 17 18```js 19import {thermal} from '@kit.BasicServicesKit'; 20``` 21 22## thermal.registerThermalLevelCallback<sup>9+</sup> 23 24registerThermalLevelCallback(callback: Callback<ThermalLevel>): void 25 26订阅热档位变化时的回调提醒。 27 28**系统能力:** SystemCapability.PowerManager.ThermalManager 29 30**参数:** 31 32| 参数名 | 类型 | 必填 | 说明 | 33| -------- | ---------------------------- | ---- | ------------------------------ | 34| callback | Callback<ThermalLevel> | 是 | 回调函数,返回变化后的热档位;该参数是一个函数类型。 | 35 36**错误码:** 37 38以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 39 40| 错误码ID | 错误信息 | 41|---------|---------| 42| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. | 43 44**示例:** 45 46```js 47try { 48 thermal.registerThermalLevelCallback((level: thermal.ThermalLevel) => { 49 console.info('thermal level is: ' + level); 50 }); 51 console.info('register thermal level callback success.'); 52} catch(err) { 53 console.error('register thermal level callback failed, err: ' + err); 54} 55``` 56 57## thermal.unregisterThermalLevelCallback<sup>9+</sup> 58 59unregisterThermalLevelCallback(callback?: Callback\<void>): void 60 61取消订阅热档位变化时的回调提醒。 62 63**系统能力:** SystemCapability.PowerManager.ThermalManager 64 65**参数:** 66 67| 参数名 | 类型 | 必填 | 说明 | 68| -------- | -------------------- | ---- | ---------------------------------------------- | 69| callback | Callback<void> | 否 | 可选参数,回调函数,无返回值。| 70 71**错误码:** 72 73以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 74 75| 错误码ID | 错误信息 | 76|---------|---------| 77| 401 | Parameter error. Possible causes: 1. Incorrect parameter types. | 78 79**示例:** 80 81```js 82try { 83 thermal.unregisterThermalLevelCallback(() => { 84 console.info('unsubscribe thermal level success.'); 85 }); 86 console.info('unregister thermal level callback success.'); 87} catch(err) { 88 console.error('unregister thermal level callback failed, err: ' + err); 89} 90``` 91 92## thermal.getLevel<sup>9+</sup> 93 94getLevel(): ThermalLevel 95 96获取当前热档位信息。 97 98**系统能力:** SystemCapability.PowerManager.ThermalManager 99 100**返回值:** 101 102| 类型 | 说明 | 103| ------------ | ------------ | 104| ThermalLevel | 热档位信息。 | 105 106**示例:** 107 108```js 109let level = thermal.getLevel(); 110console.info('thermal level is: ' + level); 111``` 112 113## thermal.subscribeThermalLevel<sup>(deprecated)</sup> 114 115subscribeThermalLevel(callback: AsyncCallback<ThermalLevel>): void 116 117> **说明:**<br>从API version 9开始不再维护,建议使用[thermal.registerThermalLevelCallback](#thermalregisterthermallevelcallback9)替代。 118 119订阅热档位变化时的回调提醒。 120 121**系统能力:** SystemCapability.PowerManager.ThermalManager 122 123**参数:** 124 125| 参数名 | 类型 | 必填 | 说明 | 126| -------- | --------------------------------- | ---- | ------------------------------------------------------------ | 127| callback | AsyncCallback<ThermalLevel> | 是 | 回调函数。AsyncCallback只返回一个参数,为热档位信息。| 128 129**示例:** 130 131```js 132thermal.subscribeThermalLevel((err: Error, level: thermal.ThermalLevel) => { 133 console.info('thermal level is: ' + level); 134}); 135``` 136 137## thermal.unsubscribeThermalLevel<sup>(deprecated)</sup> 138 139unsubscribeThermalLevel(callback?: AsyncCallback\<void>): void 140 141> **说明:**<br>从API version 9开始不再维护,建议使用[thermal.unregisterThermalLevelCallback](#thermalunregisterthermallevelcallback9)替代。 142 143取消订阅热档位变化时的回调提醒。 144 145**系统能力:** SystemCapability.PowerManager.ThermalManager 146 147**参数:** 148 149| 参数名 | 类型 | 必填 | 说明 | 150| -------- | ------------------------- | ---- | ---------------------------------------------- | 151| callback | AsyncCallback<void> | 否 | 回调函数,无返回值。不填该参数则取消所有回调。 | 152 153**示例:** 154 155```js 156thermal.unsubscribeThermalLevel(() => { 157 console.info('unsubscribe thermal level success.'); 158}); 159``` 160 161## thermal.getThermalLevel<sup>(deprecated)</sup> 162 163getThermalLevel(): ThermalLevel 164 165> **说明:**<br>从API version 9开始不再维护,建议使用[thermal.getLevel](#thermalgetlevel9)替代。 166 167获取当前热档位信息。 168 169**系统能力:** SystemCapability.PowerManager.ThermalManager 170 171**返回值:** 172 173| 类型 | 说明 | 174| ------------ | ------ | 175| ThermalLevel | 热档位信息。 | 176 177**示例:** 178 179```js 180let level = thermal.getThermalLevel(); 181console.info('thermal level is: ' + level); 182``` 183 184## ThermalLevel 185 186热档位信息。 187 188**系统能力:** SystemCapability.PowerManager.ThermalManager 189 190| 名称 | 值 | 说明 | 191| ---------- | ---- | ------------------------------------------------------------ | 192| COOL | 0 | 表明设备处于清凉状态,业务执行不受热控的限制。 | 193| NORMAL | 1 | 表明设备温度正常,但邻近温热状态,无感知业务应降低规格和负载。 | 194| WARM | 2 | 表明设备进入温热状态,无感知业务应暂停或延迟运行。 | 195| HOT | 3 | 表明设备发热明显,无感知业务应停止,非关键业务应降低规格及负载。 | 196| OVERHEATED | 4 | 表明设备发热严重,无感知业务与非关键业务应停止,前台关键业务应降低规格及负载。 | 197| WARNING | 5 | 表明设备过热即将进入紧急状态,整机资源供给大幅降低,停止所有非关键业务,前台关键业务应降低至最低规格。 | 198| EMERGENCY | 6 | 表明设备已经进入过热紧急状态,整机资源供给降至最低,设备功能受限,仅保留基础功能可用。 | 199| ESCAPE<sup>11+</sup> | 7 | 表明设备即将进入热逃生状态,所有业务将被强制停止,业务需做好逃生措施,例如保存重要数据等。 <br>**说明**: 从API version 11开始支持。|