• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.thermal (热管理)
2
3该模块提供热管理相关的接口,包括热档位查询及注册回调等功能。
4
5> **说明:**
6>
7> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8
9## 导入模块
10
11```js
12import thermal from '@ohos.thermal';
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 | If connecting to the service failed. |
36
37**示例:**
38
39```js
40try {
41    thermal.registerThermalLevelCallback((level: thermal.ThermalLevel) => {
42        console.info('thermal level is: ' + level);
43    });
44    console.info('register thermal level callback success.');
45} catch(err) {
46    console.error('register thermal level callback failed, err: ' + err);
47}
48```
49
50## thermal.unregisterThermalLevelCallback<sup>9+</sup>
51
52unregisterThermalLevelCallback(callback?: Callback\<void>): void
53
54取消订阅热档位变化时的回调提醒。
55
56**系统能力:** SystemCapability.PowerManager.ThermalManager
57
58**参数:**
59
60| 参数名   | 类型                 | 必填 | 说明                                           |
61| -------- | -------------------- | ---- | ---------------------------------------------- |
62| callback | Callback&lt;void&gt; | 否   | 回调函数,无返回值。不填该参数则取消所有回调。 |
63
64**错误码:**
65
66以下错误码的详细介绍请参见[热管理错误码](errorcode-thermal.md)。
67
68| 错误码ID   | 错误信息    |
69|---------|---------|
70| 4800101 | If connecting to the service failed. |
71
72**示例:**
73
74```js
75try {
76    thermal.unregisterThermalLevelCallback(() => {
77        console.info('unsubscribe thermal level success.');
78    });
79    console.info('unregister thermal level callback success.');
80} catch(err) {
81    console.error('unregister thermal level callback failed, err: ' + err);
82}
83```
84
85## thermal.getLevel<sup>9+</sup>
86
87getLevel(): ThermalLevel
88
89获取当前热档位信息。
90
91**系统能力:** SystemCapability.PowerManager.ThermalManager
92
93**返回值:**
94
95| 类型         | 说明         |
96| ------------ | ------------ |
97| ThermalLevel | 热档位信息。 |
98
99**错误码:**
100
101以下错误码的详细介绍请参见[热管理错误码](errorcode-thermal.md)。
102
103| 错误码ID   | 错误信息    |
104|---------|---------|
105| 4800101 | If connecting to the service failed. |
106
107**示例:**
108
109```js
110try {
111    let level = thermal.getLevel();
112    console.info('thermal level is: ' + level);
113} catch(err) {
114    console.error('get thermal level failed, err: ' + err);
115}
116```
117
118## thermal.subscribeThermalLevel<sup>(deprecated)</sup>
119
120subscribeThermalLevel(callback: AsyncCallback&lt;ThermalLevel&gt;): void
121
122> **说明:**<br>从API version 9开始不再维护,建议使用[thermal.registerThermalLevelCallback](#thermalregisterthermallevelcallback9)替代。
123
124订阅热档位变化时的回调提醒。
125
126**系统能力:** SystemCapability.PowerManager.ThermalManager
127
128**参数:**
129
130| 参数名   | 类型                              | 必填 | 说明                                                         |
131| -------- | --------------------------------- | ---- | ------------------------------------------------------------ |
132| callback | AsyncCallback&lt;ThermalLevel&gt; | 是   | 回调函数。AsyncCallback只返回一个参数,为热档位信息。|
133
134**示例:**
135
136```js
137thermal.subscribeThermalLevel((err: Error, level: thermal.ThermalLevel) => {
138    console.info('thermal level is: ' + level);
139});
140```
141
142## thermal.unsubscribeThermalLevel<sup>(deprecated)</sup>
143
144unsubscribeThermalLevel(callback?: AsyncCallback\<void>): void
145
146> **说明:**<br>从API version 9开始不再维护,建议使用[thermal.unregisterThermalLevelCallback](#thermalunregisterthermallevelcallback9)替代。
147
148取消订阅热档位变化时的回调提醒。
149
150**系统能力:** SystemCapability.PowerManager.ThermalManager
151
152**参数:**
153
154| 参数名   | 类型                      | 必填 | 说明                                           |
155| -------- | ------------------------- | ---- | ---------------------------------------------- |
156| callback | AsyncCallback&lt;void&gt; | 否   | 回调函数,无返回值。不填该参数则取消所有回调。 |
157
158**示例:**
159
160```js
161thermal.unsubscribeThermalLevel(() => {
162    console.info('unsubscribe thermal level success.');
163});
164```
165
166## thermal.getThermalLevel<sup>(deprecated)</sup>
167
168getThermalLevel(): ThermalLevel
169
170> **说明:**<br>从API version 9开始不再维护,建议使用[thermal.getLevel](#thermalgetlevel9)替代。
171
172获取当前热档位信息。
173
174**系统能力:** SystemCapability.PowerManager.ThermalManager
175
176**返回值:**
177
178| 类型           | 说明     |
179| ------------ | ------ |
180| ThermalLevel | 热档位信息。 |
181
182**示例:**
183
184```js
185let level = thermal.getThermalLevel();
186console.info('thermal level is: ' + level);
187```
188
189## ThermalLevel
190
191> **说明:**<br>枚举ESCAPE从API version 11开始支持。
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     | 7    | 表明设备即将进入热逃生状态,所有业务将被强制停止,业务需做好逃生措施,例如保存重要数据等。 |
207