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