• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 '@ohos.thermal';
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 the result.|
28
29**Error codes**
30
31For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-thermal.md).
32
33| ID  | Error Message   |
34|---------|---------|
35| 4800101 | If connecting to the service failed. |
36
37**Example**
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
54Unsubscribes from thermal level changes.
55
56**System capability:** SystemCapability.PowerManager.ThermalManager
57
58**Parameters**
59
60| Name  | Type                | Mandatory| Description                                          |
61| -------- | -------------------- | ---- | ---------------------------------------------- |
62| callback | Callback&lt;void&gt; | No  | Callback that returns no value. If this parameter is not set, all callbacks will be unregistered.|
63
64**Error codes**
65
66For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-thermal.md).
67
68| ID  | Error Message   |
69|---------|---------|
70| 4800101 | If connecting to the service failed. |
71
72**Example**
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
89Obtains the current thermal level.
90
91**System capability:** SystemCapability.PowerManager.ThermalManager
92
93**Return value**
94
95| Type        | Description        |
96| ------------ | ------------ |
97| ThermalLevel | Thermal level.|
98
99**Error codes**
100
101For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-thermal.md).
102
103| ID  | Error Message   |
104|---------|---------|
105| 4800101 | If connecting to the service failed. |
106
107**Example**
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> **NOTE**<br>This API is deprecated since API version 9. You are advised to use [thermal.registerThermalLevelCallback](#thermalregisterthermallevelcallback9).
123
124Subscribes to thermal level changes.
125
126**System capability:** SystemCapability.PowerManager.ThermalManager
127
128**Parameters**
129
130| Name  | Type                             | Mandatory| Description                                                        |
131| -------- | --------------------------------- | ---- | ------------------------------------------------------------ |
132| callback | AsyncCallback&lt;ThermalLevel&gt; | Yes  | Callback used to return the result. The return value contains only one parameter, that is, thermal level.|
133
134**Example**
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> **NOTE**<br>This API is deprecated since API version 9. You are advised to use [thermal.unregisterThermalLevelCallback](#thermalunregisterthermallevelcallback9).
147
148Unsubscribes from thermal level changes.
149
150**System capability:** SystemCapability.PowerManager.ThermalManager
151
152**Parameters**
153
154| Name  | Type                     | Mandatory| Description                                          |
155| -------- | ------------------------- | ---- | ---------------------------------------------- |
156| callback | AsyncCallback&lt;void&gt; | No  | Callback that returns no value. If this parameter is not set, all callbacks will be unregistered.|
157
158**Example**
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> **NOTE**<br>This API is deprecated since API version 9. You are advised to use [thermal.getLevel](#thermalgetlevel9).
171
172Obtains the current thermal level.
173
174**System capability:** SystemCapability.PowerManager.ThermalManager
175
176**Return value**
177
178| Type          | Description    |
179| ------------ | ------ |
180| ThermalLevel | Thermal level.|
181
182**Example**
183
184```js
185let level = thermal.getThermalLevel();
186console.info('thermal level is: ' + level);
187```
188
189## ThermalLevel
190
191> **NOTE**<br>The enum value **ESCAPE** is supported since API version 11.
192
193Represents the thermal level.
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     | 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.|
207