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**<br> 6> 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. 7 8## Modules to Import 9 10```js 11import thermal from '@ohos.thermal'; 12``` 13 14## thermal.registerThermalLevelCallback<sup>9+</sup> 15 16registerThermalLevelCallback(callback: Callback<ThermalLevel>): void 17 18Subscribes to thermal level changes. 19 20**System capability:** SystemCapability.PowerManager.ThermalManager 21 22**Parameters** 23 24| Name | Type | Mandatory| Description | 25| -------- | ---------------------------- | ---- | ------------------------------ | 26| callback | Callback<ThermalLevel> | Yes | Callback used to return the result.| 27 28**Error codes** 29 30For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-thermal.md). 31 32| Code | Error Message | 33|---------|---------| 34| 4800101 | Operation failed. Cannot connect to service.| 35 36**Example** 37 38```js 39try { 40 thermal.registerThermalLevelCallback(level => { 41 console.info('thermal level is: ' + level); 42 }); 43 console.info('register thermal level callback success.'); 44} catch(err) { 45 console.error('register thermal level callback failed, err: ' + err); 46} 47``` 48 49## thermal.unregisterThermalLevelCallback<sup>9+</sup> 50 51unregisterThermalLevelCallback(callback?: Callback\<void>): void 52 53Unsubscribes from thermal level changes. 54 55**System capability:** SystemCapability.PowerManager.ThermalManager 56 57**Parameters** 58 59| Name | Type | Mandatory| Description | 60| -------- | -------------------- | ---- | ---------------------------------------------- | 61| callback | Callback<void> | No | Callback used to return the result. No value is returned. If this parameter is not set, this API unsubscribes from all callbacks.| 62 63**Error codes** 64 65For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-thermal.md). 66 67| Code | Error Message | 68|---------|---------| 69| 4800101 | Operation failed. Cannot connect to service.| 70 71**Example** 72 73```js 74try { 75 thermal.unregisterThermalLevelCallback(() => { 76 console.info('unsubscribe thermal level success.'); 77 }); 78 console.info('unregister thermal level callback success.'); 79} catch(err) { 80 console.error('unregister thermal level callback failed, err: ' + err); 81} 82``` 83 84## thermal.getLevel<sup>9+</sup> 85 86getLevel(): ThermalLevel 87 88Obtains the current thermal level. 89 90**System capability:** SystemCapability.PowerManager.ThermalManager 91 92**Return value** 93 94| Type | Description | 95| ------------ | ------------ | 96| ThermalLevel | Thermal level obtained.| 97 98**Error codes** 99 100For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-thermal.md). 101 102| Code | Error Message | 103|---------|---------| 104| 4800101 | Operation failed. Cannot connect to service.| 105 106**Example** 107 108```js 109try { 110 var level = thermal.getLevel(); 111 console.info('thermal level is: ' + level); 112} catch(err) { 113 console.error('get thermal level failed, err: ' + err); 114} 115``` 116 117## thermal.subscribeThermalLevel<sup>(deprecated)</sup> 118 119subscribeThermalLevel(callback: AsyncCallback<ThermalLevel>): void 120 121> NOTE<br> 122> This API is deprecated since API version 9. You are advised to use [thermal.registerThermalLevelCallback](#thermalregisterthermallevelcallback9) instead. 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<ThermalLevel> | Yes | Callback used to return the result. The return value contains only one parameter, that is, thermal level. If an alarm is generated, you can use `// @ts-ignore` to suppress the alarm.| 133 134**Example** 135 136```js 137thermal.subscribeThermalLevel((level) => { 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> 147> This API is deprecated since API version 9. You are advised to use [thermal.unregisterThermalLevelCallback](#thermalunregisterthermallevelcallback9) instead. 148 149Unsubscribes from thermal level changes. 150 151**System capability:** SystemCapability.PowerManager.ThermalManager 152 153**Parameters** 154 155| Name | Type | Mandatory| Description | 156| -------- | ------------------------- | ---- | ---------------------------------------------- | 157| callback | AsyncCallback<void> | No | Callback used to return the result. No value is returned. If this parameter is not set, this API unsubscribes from all callbacks.| 158 159**Example** 160 161```js 162thermal.unsubscribeThermalLevel(() => { 163 console.info('unsubscribe thermal level success.'); 164}); 165``` 166 167## thermal.getThermalLevel<sup>(deprecated)</sup> 168 169getThermalLevel(): ThermalLevel 170 171> NOTE<br> 172> This API is deprecated since API version 9. You are advised to use [thermal.getLevel](#thermalgetlevel9) instead. 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 obtained.| 183 184**Example** 185 186```js 187var level = thermal.getThermalLevel(); 188console.info('thermal level is: ' + level); 189``` 190 191## ThermalLevel 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 operational but is not cool. You need to pay attention to its heating.| 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 other services.| 203| OVERHEATED | 4 | The device is overheated. You need to stop all imperceptible services and downgrade or reduce the load of major 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 services to the maximum extent.| 205| EMERGENCY | 6 | The device has entered the emergency state. You need to stop all services except those for the emergency help purposes.| 206