1# @ohos.thermal (Thermal Management)
2
3The **thermal** module provides thermal level-related callback and query APIs to obtain the information required for thermal control.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
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
19Subscribes to thermal level changes.
20
21**System capability:** SystemCapability.PowerManager.ThermalManager
22
23**Parameters**
24
25| Name  | Type                        | Mandatory| Description                          |
26| -------- | ---------------------------- | ---- | ------------------------------ |
27| callback | Callback&lt;ThermalLevel&gt; | Yes  | Callback used to return thermal level. This parameter is of the function type.|
28
29**Error codes**
30
31For details about the error codes, see [Thermal Manager Error Codes](errorcode-thermal.md).
32
33| ID  | Error Message   |
34|---------|---------|
35| 4800101 | Failed to connect to the service. |
36| 401     | Parameter error. Possible causes: 1.Incorrect parameter types. |
37
38**Example**
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
55Unsubscribes from thermal level changes.
56
57**System capability:** SystemCapability.PowerManager.ThermalManager
58
59**Parameters**
60
61| Name  | Type                | Mandatory| Description                                          |
62| -------- | -------------------- | ---- | ---------------------------------------------- |
63| callback | Callback&lt;void&gt; | No  | Callback that returns no value. If this parameter is not set, all callbacks will be unregistered.|
64
65**Error codes**
66
67For details about the error codes, see [Thermal Manager Error Codes](errorcode-thermal.md).
68
69| ID  | Error Message   |
70|---------|---------|
71| 4800101 | Failed to connect to the service. |
72| 401     | Parameter error. Possible causes: 1.Incorrect parameter types. |
73
74**Example**
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
91Obtains the current thermal level.
92
93**System capability:** SystemCapability.PowerManager.ThermalManager
94
95**Return value**
96
97| Type        | Description        |
98| ------------ | ------------ |
99| ThermalLevel | Thermal level.|
100
101**Error codes**
102
103For details about the error codes, see [Thermal Manager Error Codes](errorcode-thermal.md).
104
105| ID  | Error Message   |
106|---------|---------|
107| 4800101 | Failed to connect to the service. |
108
109**Example**
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> **NOTE**<br>This API is deprecated since API version 9. You are advised to use [thermal.registerThermalLevelCallback](#thermalregisterthermallevelcallback9).
125
126Subscribes to thermal level changes.
127
128**System capability:** SystemCapability.PowerManager.ThermalManager
129
130**Parameters**
131
132| Name  | Type                             | Mandatory| Description                                                        |
133| -------- | --------------------------------- | ---- | ------------------------------------------------------------ |
134| callback | AsyncCallback&lt;ThermalLevel&gt; | Yes  | Callback used to return the result. The return value contains only one parameter, that is, thermal level.|
135
136**Example**
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> **NOTE**<br>This API is deprecated since API version 9. You are advised to use [thermal.unregisterThermalLevelCallback](#thermalunregisterthermallevelcallback9).
149
150Unsubscribes from thermal level changes.
151
152**System capability:** SystemCapability.PowerManager.ThermalManager
153
154**Parameters**
155
156| Name  | Type                     | Mandatory| Description                                          |
157| -------- | ------------------------- | ---- | ---------------------------------------------- |
158| callback | AsyncCallback&lt;void&gt; | No  | Callback that returns no value. If this parameter is not set, all callbacks will be unregistered.|
159
160**Example**
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> **NOTE**<br>This API is deprecated since API version 9. You are advised to use [thermal.getLevel](#thermalgetlevel9).
173
174Obtains the current thermal level.
175
176**System capability:** SystemCapability.PowerManager.ThermalManager
177
178**Return value**
179
180| Type          | Description    |
181| ------------ | ------ |
182| ThermalLevel | Thermal level.|
183
184**Example**
185
186```js
187let level = thermal.getThermalLevel();
188console.info('thermal level is: ' + level);
189```
190
191## ThermalLevel
192
193Enumerates thermal levels.
194
195**System capability:** SystemCapability.PowerManager.ThermalManager
196
197| Name      | Value  | Description                                                        |
198| ---------- | ---- | ------------------------------------------------------------ |
199| COOL       | 0    | The device is cool, and services are not restricted.            |
200| NORMAL     | 1    | The device is in the normal temperature range but it is getting warm. You need to downgrade or reduce the load of imperceptible services.|
201| WARM       | 2    | The device is warm. You need to stop or delay some imperceptible services.|
202| HOT        | 3    | The device is heating up. You need to stop all imperceptible services and downgrade or reduce the load of non-critical services.|
203| OVERHEATED | 4    | The device is overheated. You need to stop all imperceptible services and downgrade or reduce the load of major foreground services.|
204| WARNING    | 5    | The device is overheated and is about to enter the emergency state. You need to stop all imperceptible services and downgrade major foreground services to the maximum extent.|
205| EMERGENCY  | 6    | The device has entered the emergency state. You need to stop all services except those for fundamental use.|
206| ESCAPE<sup>11+</sup>     | 7    | The device is about to enter the escape state. You need to stop all services and take necessary emergency measures such as data backup.<br>Note: This API is supported since API version 11.|
207