js-apis-thermal.md 6.5 KB
Newer Older
1
# @ohos.thermal (热管理)
Q
q00569459 已提交
2

3 4
该模块提供热管理相关的接口,包括热档位查询及注册回调等功能。

5 6
> **说明:**
>
Q
q00569459 已提交
7
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
Z
zengyawen 已提交
8

Q
q00569459 已提交
9 10
## 导入模块

A
aqxyjay 已提交
11
```js
Q
q00569459 已提交
12 13 14
import thermal from '@ohos.thermal';
```

A
aqxyjay 已提交
15 16 17
## thermal.registerThermalLevelCallback<sup>9+</sup>

registerThermalLevelCallback(callback: Callback&lt;ThermalLevel&gt;): void
Q
q00569459 已提交
18 19 20

订阅热档位变化时的回调提醒。

21
**系统能力:** SystemCapability.PowerManager.ThermalManager
Q
q00569459 已提交
22

Q
q00569459 已提交
23 24
**参数:**

A
aqxyjay 已提交
25 26 27 28 29 30 31 32 33 34
| 参数名   | 类型                         | 必填 | 说明                           |
| -------- | ---------------------------- | ---- | ------------------------------ |
| callback | Callback&lt;ThermalLevel&gt; | 是   | 回调函数,返回变化后的热档位。 |

**错误码:**

以下错误码的详细介绍请参见[耗电统计错误码](../errorcodes/errorcode-thermal.md)

| 错误码ID   | 错误信息    |
|---------|---------|
W
wangwang 已提交
35
| 4800101 | If connecting to the service failed. |
Q
q00569459 已提交
36 37 38

**示例:**

A
aqxyjay 已提交
39
```js
A
aqxyjay 已提交
40 41 42 43 44 45 46 47
try {
    thermal.registerThermalLevelCallback(level => {
        console.info('thermal level is: ' + level);
    });
    console.info('register thermal level callback success.');
} catch(err) {
    console.error('register thermal level callback failed, err: ' + err);
}
Q
q00569459 已提交
48 49
```

A
aqxyjay 已提交
50 51 52 53 54 55 56 57 58 59 60 61
## thermal.unregisterThermalLevelCallback<sup>9+</sup>

unregisterThermalLevelCallback(callback?: Callback\<void>): void

取消订阅热档位变化时的回调提醒。

**系统能力:** SystemCapability.PowerManager.ThermalManager

**参数:**

| 参数名   | 类型                 | 必填 | 说明                                           |
| -------- | -------------------- | ---- | ---------------------------------------------- |
A
aqxyjay 已提交
62
| callback | Callback&lt;void&gt; | 否   | 回调函数,无返回值。不填该参数则取消所有回调。 |
A
aqxyjay 已提交
63 64 65 66 67 68 69

**错误码:**

以下错误码的详细介绍请参见[热管理错误码](../errorcodes/errorcode-thermal.md)

| 错误码ID   | 错误信息    |
|---------|---------|
W
wangwang 已提交
70
| 4800101 | If connecting to the service failed. |
A
aqxyjay 已提交
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104

**示例:**

```js
try {
    thermal.unregisterThermalLevelCallback(() => {
        console.info('unsubscribe thermal level success.');
    });
    console.info('unregister thermal level callback success.');
} catch(err) {
    console.error('unregister thermal level callback failed, err: ' + err);
}
```

## thermal.getLevel<sup>9+</sup>

getLevel(): ThermalLevel

获取当前热档位信息。

**系统能力:** SystemCapability.PowerManager.ThermalManager

**返回值:**

| 类型         | 说明         |
| ------------ | ------------ |
| ThermalLevel | 热档位信息。 |

**错误码:**

以下错误码的详细介绍请参见[热管理错误码](../errorcodes/errorcode-thermal.md)

| 错误码ID   | 错误信息    |
|---------|---------|
W
wangwang 已提交
105
| 4800101 | If connecting to the service failed. |
A
aqxyjay 已提交
106 107 108 109 110 111 112 113 114 115 116 117

**示例:**

```js
try {
    var level = thermal.getLevel();
    console.info('thermal level is: ' + level);
} catch(err) {
    console.error('get thermal level failed, err: ' + err);
}
```

A
aqxyjay 已提交
118 119 120 121
## thermal.subscribeThermalLevel<sup>(deprecated)</sup>

subscribeThermalLevel(callback: AsyncCallback&lt;ThermalLevel&gt;): void

122
> **说明:**<br>从API version 9开始不再维护,建议使用[thermal.registerThermalLevelCallback](#thermalregisterthermallevelcallback9)替代。
A
aqxyjay 已提交
123 124 125 126 127 128 129 130 131

订阅热档位变化时的回调提醒。

**系统能力:** SystemCapability.PowerManager.ThermalManager

**参数:**

| 参数名   | 类型                              | 必填 | 说明                                                         |
| -------- | --------------------------------- | ---- | ------------------------------------------------------------ |
132
| callback | AsyncCallback&lt;ThermalLevel&gt; | 是   | 回调函数。AsyncCallback只返回一个参数,为热档位信息。|
A
aqxyjay 已提交
133 134 135 136 137 138 139 140 141 142 143 144 145

**示例:**

```js
thermal.subscribeThermalLevel((level) => {
    console.info('thermal level is: ' + level);
});
```

## thermal.unsubscribeThermalLevel<sup>(deprecated)</sup>

unsubscribeThermalLevel(callback?: AsyncCallback\<void>): void

146
> **说明:**<br>从API version 9开始不再维护,建议使用[thermal.unregisterThermalLevelCallback](#thermalunregisterthermallevelcallback9)替代。
A
aqxyjay 已提交
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169

取消订阅热档位变化时的回调提醒。

**系统能力:** SystemCapability.PowerManager.ThermalManager

**参数:**

| 参数名   | 类型                      | 必填 | 说明                                           |
| -------- | ------------------------- | ---- | ---------------------------------------------- |
| callback | AsyncCallback&lt;void&gt; | 否   | 回调函数,无返回值。不填该参数则取消所有回调。 |

**示例:**

```js
thermal.unsubscribeThermalLevel(() => {
    console.info('unsubscribe thermal level success.');
});
```

## thermal.getThermalLevel<sup>(deprecated)</sup>

getThermalLevel(): ThermalLevel

170
> **说明:**<br>从API version 9开始不再维护,建议使用[thermal.getLevel](#thermalgetlevel9)替代。
A
aqxyjay 已提交
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188

获取当前热档位信息。

**系统能力:** SystemCapability.PowerManager.ThermalManager

**返回值:**

| 类型           | 说明     |
| ------------ | ------ |
| ThermalLevel | 热档位信息。 |

**示例:**

```js
var level = thermal.getThermalLevel();
console.info('thermal level is: ' + level);
```

A
aqxyjay 已提交
189 190 191 192 193 194
## ThermalLevel

热档位信息。

**系统能力:** SystemCapability.PowerManager.ThermalManager

A
aqxyjay 已提交
195 196 197 198 199 200 201 202 203
| 名称       | 值   | 说明                                                         |
| ---------- | ---- | ------------------------------------------------------------ |
| COOL       | 0    | 表明设备处于低温的状态,业务执行不受热控的限制。             |
| NORMAL     | 1    | 表明设备处于正常工作状态,但温度不低,需要注意是否临近发热状态 |
| WARM       | 2    | 表明设备已经进入温热状态,部分无感知业务需要考虑停止或延迟执行。 |
| HOT        | 3    | 表明设备已经明显发热,无感知业务应全面停止,其他业务应考虑降规格及负载。 |
| OVERHEATED | 4    | 表明设备已经发热严重,无感知业务应全面停止,主要业务需降低规格及负载。 |
| WARNING    | 5    | 表明设备已经发热严重并且即将进入紧急状态,无感知业务应全面停止,主要业务应降低至最低规格。 |
| EMERGENCY  | 6    | 表明设备已经进入紧急状态,所有业务应当全面停止工作,可保留部分紧急求助功能。 |