1e41f4b71Sopenharmony_ci# @ohos.thermal (Thermal Management)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **thermal** module provides thermal level-related callback and query APIs to obtain the information required for thermal control.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> 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.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci## Modules to Import
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci```js
12e41f4b71Sopenharmony_ciimport {thermal} from '@kit.BasicServicesKit';
13e41f4b71Sopenharmony_ci```
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## thermal.registerThermalLevelCallback<sup>9+</sup>
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ciregisterThermalLevelCallback(callback: Callback&lt;ThermalLevel&gt;): void
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ciSubscribes to thermal level changes.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci**System capability:** SystemCapability.PowerManager.ThermalManager
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci**Parameters**
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci| Name  | Type                        | Mandatory| Description                          |
26e41f4b71Sopenharmony_ci| -------- | ---------------------------- | ---- | ------------------------------ |
27e41f4b71Sopenharmony_ci| callback | Callback&lt;ThermalLevel&gt; | Yes  | Callback used to return thermal level. This parameter is of the function type.|
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**Error codes**
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ciFor details about the error codes, see [Thermal Manager Error Codes](errorcode-thermal.md).
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci| ID  | Error Message   |
34e41f4b71Sopenharmony_ci|---------|---------|
35e41f4b71Sopenharmony_ci| 4800101 | Failed to connect to the service. |
36e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Incorrect parameter types. |
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci**Example**
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci```js
41e41f4b71Sopenharmony_citry {
42e41f4b71Sopenharmony_ci    thermal.registerThermalLevelCallback((level: thermal.ThermalLevel) => {
43e41f4b71Sopenharmony_ci        console.info('thermal level is: ' + level);
44e41f4b71Sopenharmony_ci    });
45e41f4b71Sopenharmony_ci    console.info('register thermal level callback success.');
46e41f4b71Sopenharmony_ci} catch(err) {
47e41f4b71Sopenharmony_ci    console.error('register thermal level callback failed, err: ' + err);
48e41f4b71Sopenharmony_ci}
49e41f4b71Sopenharmony_ci```
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci## thermal.unregisterThermalLevelCallback<sup>9+</sup>
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ciunregisterThermalLevelCallback(callback?: Callback\<void>): void
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ciUnsubscribes from thermal level changes.
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci**System capability:** SystemCapability.PowerManager.ThermalManager
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci**Parameters**
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci| Name  | Type                | Mandatory| Description                                          |
62e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ---------------------------------------------- |
63e41f4b71Sopenharmony_ci| callback | Callback&lt;void&gt; | No  | Callback that returns no value. If this parameter is not set, all callbacks will be unregistered.|
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci**Error codes**
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ciFor details about the error codes, see [Thermal Manager Error Codes](errorcode-thermal.md).
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci| ID  | Error Message   |
70e41f4b71Sopenharmony_ci|---------|---------|
71e41f4b71Sopenharmony_ci| 4800101 | Failed to connect to the service. |
72e41f4b71Sopenharmony_ci| 401     | Parameter error. Possible causes: 1.Incorrect parameter types. |
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci**Example**
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci```js
77e41f4b71Sopenharmony_citry {
78e41f4b71Sopenharmony_ci    thermal.unregisterThermalLevelCallback(() => {
79e41f4b71Sopenharmony_ci        console.info('unsubscribe thermal level success.');
80e41f4b71Sopenharmony_ci    });
81e41f4b71Sopenharmony_ci    console.info('unregister thermal level callback success.');
82e41f4b71Sopenharmony_ci} catch(err) {
83e41f4b71Sopenharmony_ci    console.error('unregister thermal level callback failed, err: ' + err);
84e41f4b71Sopenharmony_ci}
85e41f4b71Sopenharmony_ci```
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci## thermal.getLevel<sup>9+</sup>
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_cigetLevel(): ThermalLevel
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ciObtains the current thermal level.
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci**System capability:** SystemCapability.PowerManager.ThermalManager
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci**Return value**
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci| Type        | Description        |
98e41f4b71Sopenharmony_ci| ------------ | ------------ |
99e41f4b71Sopenharmony_ci| ThermalLevel | Thermal level.|
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ci**Error codes**
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ciFor details about the error codes, see [Thermal Manager Error Codes](errorcode-thermal.md).
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci| ID  | Error Message   |
106e41f4b71Sopenharmony_ci|---------|---------|
107e41f4b71Sopenharmony_ci| 4800101 | Failed to connect to the service. |
108e41f4b71Sopenharmony_ci
109e41f4b71Sopenharmony_ci**Example**
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ci```js
112e41f4b71Sopenharmony_citry {
113e41f4b71Sopenharmony_ci    let level = thermal.getLevel();
114e41f4b71Sopenharmony_ci    console.info('thermal level is: ' + level);
115e41f4b71Sopenharmony_ci} catch(err) {
116e41f4b71Sopenharmony_ci    console.error('get thermal level failed, err: ' + err);
117e41f4b71Sopenharmony_ci}
118e41f4b71Sopenharmony_ci```
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci## thermal.subscribeThermalLevel<sup>(deprecated)</sup>
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_cisubscribeThermalLevel(callback: AsyncCallback&lt;ThermalLevel&gt;): void
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci> **NOTE**<br>This API is deprecated since API version 9. You are advised to use [thermal.registerThermalLevelCallback](#thermalregisterthermallevelcallback9).
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ciSubscribes to thermal level changes.
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci**System capability:** SystemCapability.PowerManager.ThermalManager
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci**Parameters**
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci| Name  | Type                             | Mandatory| Description                                                        |
133e41f4b71Sopenharmony_ci| -------- | --------------------------------- | ---- | ------------------------------------------------------------ |
134e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;ThermalLevel&gt; | Yes  | Callback used to return the result. The return value contains only one parameter, that is, thermal level.|
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci**Example**
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci```js
139e41f4b71Sopenharmony_cithermal.subscribeThermalLevel((err: Error, level: thermal.ThermalLevel) => {
140e41f4b71Sopenharmony_ci    console.info('thermal level is: ' + level);
141e41f4b71Sopenharmony_ci});
142e41f4b71Sopenharmony_ci```
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci## thermal.unsubscribeThermalLevel<sup>(deprecated)</sup>
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_ciunsubscribeThermalLevel(callback?: AsyncCallback\<void>): void
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci> **NOTE**<br>This API is deprecated since API version 9. You are advised to use [thermal.unregisterThermalLevelCallback](#thermalunregisterthermallevelcallback9).
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_ciUnsubscribes from thermal level changes.
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_ci**System capability:** SystemCapability.PowerManager.ThermalManager
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_ci**Parameters**
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci| Name  | Type                     | Mandatory| Description                                          |
157e41f4b71Sopenharmony_ci| -------- | ------------------------- | ---- | ---------------------------------------------- |
158e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | No  | Callback that returns no value. If this parameter is not set, all callbacks will be unregistered.|
159e41f4b71Sopenharmony_ci
160e41f4b71Sopenharmony_ci**Example**
161e41f4b71Sopenharmony_ci
162e41f4b71Sopenharmony_ci```js
163e41f4b71Sopenharmony_cithermal.unsubscribeThermalLevel(() => {
164e41f4b71Sopenharmony_ci    console.info('unsubscribe thermal level success.');
165e41f4b71Sopenharmony_ci});
166e41f4b71Sopenharmony_ci```
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci## thermal.getThermalLevel<sup>(deprecated)</sup>
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_cigetThermalLevel(): ThermalLevel
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci> **NOTE**<br>This API is deprecated since API version 9. You are advised to use [thermal.getLevel](#thermalgetlevel9).
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ciObtains the current thermal level.
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ci**System capability:** SystemCapability.PowerManager.ThermalManager
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci**Return value**
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci| Type          | Description    |
181e41f4b71Sopenharmony_ci| ------------ | ------ |
182e41f4b71Sopenharmony_ci| ThermalLevel | Thermal level.|
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci**Example**
185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_ci```js
187e41f4b71Sopenharmony_cilet level = thermal.getThermalLevel();
188e41f4b71Sopenharmony_ciconsole.info('thermal level is: ' + level);
189e41f4b71Sopenharmony_ci```
190e41f4b71Sopenharmony_ci
191e41f4b71Sopenharmony_ci## ThermalLevel
192e41f4b71Sopenharmony_ci
193e41f4b71Sopenharmony_ciEnumerates thermal levels.
194e41f4b71Sopenharmony_ci
195e41f4b71Sopenharmony_ci**System capability:** SystemCapability.PowerManager.ThermalManager
196e41f4b71Sopenharmony_ci
197e41f4b71Sopenharmony_ci| Name      | Value  | Description                                                        |
198e41f4b71Sopenharmony_ci| ---------- | ---- | ------------------------------------------------------------ |
199e41f4b71Sopenharmony_ci| COOL       | 0    | The device is cool, and services are not restricted.            |
200e41f4b71Sopenharmony_ci| 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.|
201e41f4b71Sopenharmony_ci| WARM       | 2    | The device is warm. You need to stop or delay some imperceptible services.|
202e41f4b71Sopenharmony_ci| HOT        | 3    | The device is heating up. You need to stop all imperceptible services and downgrade or reduce the load of non-critical services.|
203e41f4b71Sopenharmony_ci| OVERHEATED | 4    | The device is overheated. You need to stop all imperceptible services and downgrade or reduce the load of major foreground services.|
204e41f4b71Sopenharmony_ci| 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.|
205e41f4b71Sopenharmony_ci| EMERGENCY  | 6    | The device has entered the emergency state. You need to stop all services except those for fundamental use.|
206e41f4b71Sopenharmony_ci| 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