js-apis-resourceschedule-backgroundTaskManager.md 26.2 KB
Newer Older
1
# @ohos.resourceschedule.backgroundTaskManager (Background Task Management)
2

G
Gloria 已提交
3
The **backgroundTaskManager** module provides APIs to request background tasks. You can use the APIs to request transient tasks, continuous tasks, or efficiency resources to prevent the application process from being terminated or suspended when your application is switched to the background.
4 5

>  **NOTE**
G
Gloria 已提交
6
> 
G
Gloria 已提交
7
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8 9 10 11 12 13 14 15 16 17 18 19


## Modules to Import

```js
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';  
```

## backgroundTaskManager.requestSuspendDelay

requestSuspendDelay(reason: string, callback: Callback<void>): DelaySuspendInfo

G
Gloria 已提交
20
Requests a transient task.
21

G
Gloria 已提交
22 23 24
>  **NOTE**
> 
> The maximum duration of a transient task is 3 minutes in normal cases. In the case of a [low battery](js-apis-battery-info.md), the maximum duration is decreased to 1 minute.
25 26 27 28 29 30 31

**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask

**Parameters**

| Name     | Type                  | Mandatory  | Description                            |
| -------- | -------------------- | ---- | ------------------------------ |
G
Gloria 已提交
32 33
| reason   | string               | Yes   | Reason for requesting the transient task.                    |
| callback | Callback<void> | Yes   | Callback used to notify the application that the transient task is about to time out. Generally, the callback is invoked 6 seconds before the timeout.|
34 35 36 37 38

**Return value**

| Type                                   | Description       |
| ------------------------------------- | --------- |
G
Gloria 已提交
39
| [DelaySuspendInfo](#delaysuspendinfo) | Information about the transient task.|
40 41 42 43 44 45 46 47 48

**Error codes**

For details about the error codes, see [backgroundTaskManager Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).

| ID | Error Message            |
| ---- | --------------------- |
| 9800001 | Memory operation failed. |
| 9800002 | Parcel operation failed. |
G
Gloria 已提交
49
| 9800003 | Inner transact failed. | |
50
| 9800004 | System service operation failed. |
G
Gloria 已提交
51 52
| 9900001 | Caller information verification failed. |
| 9900002 | Background task verification failed. |
53 54 55 56 57 58 59 60 61 62 63

**Example**

  ```js
  import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';  

  let myReason = 'test requestSuspendDelay';
  try {
    let delayInfo = backgroundTaskManager.requestSuspendDelay(myReason, () => {
        console.info("Request suspension delay will time out.");
    })
G
Gloria 已提交
64 65
    let id = delayInfo.requestId;
    let time = delayInfo.actualDelayTime;
66 67 68 69 70 71 72 73
    console.info("The requestId is: " + id);
    console.info("The actualDelayTime is: " + time);
  } catch (error) {
    console.error(`requestSuspendDelay failed. code is ${error.code} message is ${error.message}`);
  }
  ```


G
Gloria 已提交
74
## backgroundTaskManager.getRemainingDelayTime
75 76 77

getRemainingDelayTime(requestId: number, callback: AsyncCallback<number>): void

G
Gloria 已提交
78
Obtains the remaining time of a transient task. This API uses an asynchronous callback to return the result.
79 80 81 82 83 84 85

**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask

**Parameters**

| Name      | Type                         | Mandatory  | Description                                      |
| --------- | --------------------------- | ---- | ---------------------------------------- |
G
Gloria 已提交
86 87
| requestId | number                      | Yes   | Request ID of the transient task.                              |
| callback  | AsyncCallback<number> | Yes   | Callback used to return the remaining time, in milliseconds.|
88 89 90 91 92 93 94 95 96

**Error codes**

For details about the error codes, see [backgroundTaskManager Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).

| ID | Error Message            |
| ---- | --------------------- |
| 9800001 | Memory operation failed. |
| 9800002 | Parcel operation failed. |
G
Gloria 已提交
97
| 9800003 | Inner transact failed.  |
98
| 9800004 | System service operation failed. |
G
Gloria 已提交
99 100
| 9900001 | Caller information verification failed. |
| 9900002 | Background task verification failed. |
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122


**Example**

  ```js
  import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';  

  let id = 1;
  try {
    backgroundTaskManager.getRemainingDelayTime(id, (error, res) => {
        if(error) {
            console.error(`callback => Operation getRemainingDelayTime failed. code is ${error.code} message is ${error.message}`);
        } else {
            console.log('callback => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res));
        }
    })
  } catch (error) {
    console.error(`callback => Operation getRemainingDelayTime failed. code is ${error.code} message is ${error.message}`);
  }
  ```


G
Gloria 已提交
123
## backgroundTaskManager.getRemainingDelayTime
124 125 126

getRemainingDelayTime(requestId: number): Promise<number>

G
Gloria 已提交
127
Obtains the remaining time of a transient task. This API uses a promise to return the result.
128 129 130 131 132 133 134

**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask

**Parameters**

| Name      | Type    | Mandatory  | Description        |
| --------- | ------ | ---- | ---------- |
G
Gloria 已提交
135
| requestId | number | Yes   | Request ID of the transient task.|
136 137 138 139 140

**Return value**

| Type                   | Description                                      |
| --------------------- | ---------------------------------------- |
G
Gloria 已提交
141
| Promise<number> | Promise used to return the remaining time, in milliseconds.|
142 143 144 145 146 147 148 149 150

**Error codes**

For details about the error codes, see [backgroundTaskManager Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).

| ID | Error Message            |
| ---- | --------------------- |
| 9800001 | Memory operation failed. |
| 9800002 | Parcel operation failed. |
G
Gloria 已提交
151
| 9800003 | Inner transact failed. | |
152
| 9800004 | System service operation failed. |
G
Gloria 已提交
153 154
| 9900001 | Caller information verification failed. |
| 9900002 | Background task verification failed. |
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177

**Example**

  ```js
  import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';  

  let id = 1;
  try {
    backgroundTaskManager.getRemainingDelayTime(id).then( res => {
        console.log('promise => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res));
    }).catch( error => {
        console.error(`promise => Operation getRemainingDelayTime failed. code is ${error.code} message is ${error.message}`);
    })
  } catch (error) {
    console.error(`promise => Operation getRemainingDelayTime failed. code is ${error.code} message is ${error.message}`);
  }
  ```


## backgroundTaskManager.cancelSuspendDelay

cancelSuspendDelay(requestId: number): void

G
Gloria 已提交
178
Cancels a transient task.
179 180 181 182 183 184 185

**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask

**Parameters**

| Name      | Type    | Mandatory  | Description        |
| --------- | ------ | ---- | ---------- |
G
Gloria 已提交
186
| requestId | number | Yes   | Request ID of the transient task.|
187 188 189 190 191 192 193 194 195

**Error codes**

For details about the error codes, see [backgroundTaskManager Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).

| ID | Error Message            |
| ---- | --------------------- |
| 9800001 | Memory operation failed. |
| 9800002 | Parcel operation failed. |
G
Gloria 已提交
196
| 9800003 | Inner transact failed. | |
197
| 9800004 | System service operation failed. |
G
Gloria 已提交
198 199
| 9900001 | Caller information verification failed. |
| 9900002 | Background task verification failed. |
200 201 202 203 204 205 206 207 208 209 210 211 212 213

**Example**

  ```js
  import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';  

  let id = 1;
  try {
    backgroundTaskManager.cancelSuspendDelay(id);
  } catch (error) {
    console.error(`cancelSuspendDelay failed. code is ${error.code} message is ${error.message}`);
  }
  ```

G
Gloria 已提交
214
## backgroundTaskManager.startBackgroundRunning
215 216 217

startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent, callback: AsyncCallback<void>): void

G
Gloria 已提交
218
Requests a continuous task. This API uses an asynchronous callback to return the result.
219 220 221 222 223 224 225 226 227

**Required permissions**: ohos.permission.KEEP_BACKGROUND_RUNNING

**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask

**Parameters**

| Name      | Type                                | Mandatory  | Description                                      |
| --------- | ---------------------------------- | ---- | ---------------------------------------- |
G
Gloria 已提交
228
| context   | Context                            | Yes   | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-context.md).|
G
Gloria 已提交
229 230 231
| bgMode    | [BackgroundMode](#backgroundmode) | Yes   | Continuous task mode.                             |
| wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes   | Notification parameters, which are used to specify the target page that is redirected to when a continuous task notification is clicked.          |
| callback  | AsyncCallback&lt;void&gt;          | Yes   | Callback used to return the result. If the continuous task is requested, **err** is **undefined**. Otherwise, **err** is an error object.   |
232 233 234 235 236 237 238 239 240

**Error codes**

For details about the error codes, see [backgroundTaskManager Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).

| ID | Error Message            |
| ---- | --------------------- |
| 9800001 | Memory operation failed. |
| 9800002 | Parcel operation failed. |
G
Gloria 已提交
241
| 9800003 | Inner transact failed. | |
242
| 9800004 | System service operation failed. |
G
Gloria 已提交
243
| 9800005 | Background task verification failed. |
244 245 246 247 248 249
| 9800006 | Notification verification failed. |
| 9800007 | Task storage failed. |

**Example**

```js
250
import UIAbility from '@ohos.app.ability.UIAbility';
251
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';  
G
Gloria 已提交
252
import wantAgent from '@ohos.app.ability.wantAgent';
253 254 255 256 257 258 259 260 261

function callback(error, data) {
    if (error) {
        console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
    } else {
        console.info("Operation startBackgroundRunning succeeded");
    }
}

262
export default class EntryAbility extends UIAbility {
263 264 265 266 267
    onCreate(want, launchParam) {
        let wantAgentInfo = {
            wants: [
                {
                    bundleName: "com.example.myapplication",
268
                    abilityName: "EntryAbility"
269 270 271 272 273 274 275
                }
            ],
            operationType: wantAgent.OperationType.START_ABILITY,
            requestCode: 0,
            wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
        };

G
Gloria 已提交
276 277 278 279 280 281 282 283 284 285 286 287
        try {
            wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
                try {
                    backgroundTaskManager.startBackgroundRunning(this.context,
                        backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj, callback)
                } catch (error) {
                    console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
                }
            });
        } catch (error) {
            console.error(`Operation getWantAgent failed. code is ${error.code} message is ${error.message}`);
        }
288 289 290 291
    }
};
```

G
Gloria 已提交
292
## backgroundTaskManager.startBackgroundRunning
293 294 295

startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent): Promise&lt;void&gt;

G
Gloria 已提交
296
Requests a continuous task. This API uses a promise to return the result.
297 298 299 300 301 302 303 304 305

**Required permissions**: ohos.permission.KEEP_BACKGROUND_RUNNING

**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask

**Parameters**

| Name      | Type                                | Mandatory  | Description                                      |
| --------- | ---------------------------------- | ---- | ---------------------------------------- |
G
Gloria 已提交
306
| context   | Context                            | Yes   | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-context.md).|
G
Gloria 已提交
307 308
| bgMode    | [BackgroundMode](#backgroundmode) | Yes   | Continuous task mode.                             |
| wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes   | Notification parameters, which are used to specify the target page that is redirected to when a continuous task notification is clicked.                |
309 310 311 312 313

**Return value**

| Type            | Description              |
| -------------- | ---------------- |
G
Gloria 已提交
314
| Promise\<void> | Promise that returns no value.|
315 316 317 318 319 320 321 322 323

**Error codes**

For details about the error codes, see [backgroundTaskManager Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).

| ID | Error Message            |
| ---- | --------------------- |
| 9800001 | Memory operation failed. |
| 9800002 | Parcel operation failed. |
G
Gloria 已提交
324
| 9800003 | Inner transact failed. | |
325
| 9800004 | System service operation failed. |
G
Gloria 已提交
326
| 9800005 | Background task verification failed. |
327 328 329 330 331 332
| 9800006 | Notification verification failed. |
| 9800007 | Task storage failed. |

**Example**

```js
333
import UIAbility from '@ohos.app.ability.UIAbility';
334
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'; 
G
Gloria 已提交
335
import wantAgent from '@ohos.app.ability.wantAgent';
336

337
export default class EntryAbility extends UIAbility {
338 339 340 341 342
    onCreate(want, launchParam) {
        let wantAgentInfo = {
            wants: [
                {
                    bundleName: "com.example.myapplication",
343
                    abilityName: "EntryAbility"
344 345 346 347 348 349 350
                }
            ],
            operationType: wantAgent.OperationType.START_ABILITY,
            requestCode: 0,
            wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
        };

G
Gloria 已提交
351 352 353 354 355 356 357 358 359 360
        try {
            wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
                try {
                    backgroundTaskManager.startBackgroundRunning(this.context,
                        backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj).then(() => {
                        console.info("Operation startBackgroundRunning succeeded");
                    }).catch((error) => {
                        console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
                    });
                } catch (error) {
361
                    console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
G
Gloria 已提交
362 363 364 365 366
                }
            });
        } catch (error) {
            console.error(`Operation getWantAgent failed. code is ${error.code} message is ${error.message}`);
        }
367 368 369 370
    }
};
```

G
Gloria 已提交
371
## backgroundTaskManager.stopBackgroundRunning
372 373 374

stopBackgroundRunning(context: Context, callback: AsyncCallback&lt;void&gt;): void

G
Gloria 已提交
375
Cancels a continuous task. This API uses an asynchronous callback to return the result.
376 377 378 379 380 381 382

**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask

**Parameters**

| Name     | Type                       | Mandatory  | Description                                      |
| -------- | ------------------------- | ---- | ---------------------------------------- |
G
Gloria 已提交
383
| context  | Context                   | Yes   | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-context.md).|
G
Gloria 已提交
384
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback used to return the result. If the continuous task is canceled, **err** is **undefined**. Otherwise, **err** is an error object.|
385 386 387 388 389 390 391 392 393

**Error codes**

For details about the error codes, see [backgroundTaskManager Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).

| ID | Error Message            |
| ---- | --------------------- |
| 9800001 | Memory operation failed. |
| 9800002 | Parcel operation failed. |
G
Gloria 已提交
394
| 9800003 | Inner transact failed. | |
395
| 9800004 | System service operation failed. |
G
Gloria 已提交
396
| 9800005 | Background task verification failed. |
397 398 399 400 401 402
| 9800006 | Notification verification failed. |
| 9800007 | Task storage failed. |

**Example**

```js
403
import UIAbility from '@ohos.app.ability.UIAbility';
404 405 406 407 408 409 410 411 412 413
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';  

function callback(error, data) {
    if (error) {
        console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
    } else {
        console.info("Operation stopBackgroundRunning succeeded");
    }
}

414
export default class EntryAbility extends UIAbility {
415 416 417 418 419 420 421 422 423 424
    onCreate(want, launchParam) {
        try {
            backgroundTaskManager.stopBackgroundRunning(this.context, callback);
        } catch (error) {
            console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
        }
    }
};
```

G
Gloria 已提交
425
## backgroundTaskManager.stopBackgroundRunning
426 427 428

stopBackgroundRunning(context: Context): Promise&lt;void&gt;

G
Gloria 已提交
429
Cancels a continuous task. This API uses a promise to return the result.
430 431 432 433 434 435 436

**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask

**Parameters**

| Name    | Type     | Mandatory  | Description                                      |
| ------- | ------- | ---- | ---------------------------------------- |
G
Gloria 已提交
437
| context | Context | Yes   | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-context.md).|
438 439 440 441 442

**Return value**

| Type            | Description              |
| -------------- | ---------------- |
G
Gloria 已提交
443
| Promise\<void> | Promise that returns no value.|
444 445 446 447 448 449 450 451 452

**Error codes**

For details about the error codes, see [backgroundTaskManager Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).

| ID | Error Message            |
| ---- | --------------------- |
| 9800001 | Memory operation failed. |
| 9800002 | Parcel operation failed. |
G
Gloria 已提交
453
| 9800003 | Inner transact failed. | |
454
| 9800004 | System service operation failed. |
G
Gloria 已提交
455
| 9800005 | Background task verification failed. |
456 457 458 459 460 461
| 9800006 | Notification verification failed. |
| 9800007 | Task storage failed. |

**Example**

```js
462
import UIAbility from '@ohos.app.ability.UIAbility';
463 464
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';  

465
export default class EntryAbility extends UIAbility {
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
    onCreate(want, launchParam) {
        try {
            backgroundTaskManager.stopBackgroundRunning(this.context).then(() => {
                console.info("Operation stopBackgroundRunning succeeded");
            }).catch((error) => {
                console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
            });
        } catch (error) {
            console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
        }
    }
};
```

## backgroundTaskManager.applyEfficiencyResources

G
Gloria 已提交
482
applyEfficiencyResources(request: EfficiencyResourcesRequest): void
483

G
Gloria 已提交
484
Requests efficiency resources.
485 486 487 488 489 490 491 492 493

**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply

**System API**: This is a system API.

**Parameters**

| Name    | Type     | Mandatory  | Description                                      |
| ------- | ------- | ---- | ---------------------------------------- |
G
Gloria 已提交
494
| request | [EfficiencyResourcesRequest](#efficiencyresourcesrequest) | Yes   | Necessary information carried in the request, including the resource type and timeout interval.|
495 496 497 498 499 500 501 502 503 504


**Error codes**

For details about the error codes, see [backgroundTaskManager Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).

| ID | Error Message            |
| ---- | --------------------- |
| 9800001 | Memory operation failed. |
| 9800002 | Parcel operation failed. |
G
Gloria 已提交
505
| 9800003 | Inner transact failed. | |
506
| 9800004 | System service operation failed. |
G
Gloria 已提交
507
| 18700001 | Caller information verification failed. |
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533

**Example**

```js
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';  

let request = {
    resourceTypes: backgroundTaskManager.ResourceType.CPU,
    isApply: true,
    timeOut: 0,
    reason: "apply",
    isPersist: true,
    isProcess: false,
};
try {
    backgroundTaskManager.applyEfficiencyResources(request);
    console.info("applyEfficiencyResources success. ");
} catch (error) {
    console.error(`applyEfficiencyResources failed. code is ${error.code} message is ${error.message}`);
}
```

## backgroundTaskManager.resetAllEfficiencyResources

resetAllEfficiencyResources(): void

G
Gloria 已提交
534
Releases all efficiency resources.
535 536 537 538 539 540 541 542 543 544 545 546 547

**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply

**System API**: This is a system API.

**Error codes**

For details about the error codes, see [backgroundTaskManager Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).

| ID | Error Message            |
| ---- | --------------------- |
| 9800001 | Memory operation failed. |
| 9800002 | Parcel operation failed. |
G
Gloria 已提交
548
| 9800003 | Inner transact failed. | |
549
| 9800004 | System service operation failed. |
G
Gloria 已提交
550
| 18700001 | Caller information verification failed. |
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565

**Example**

```js
import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';  

try {
    backgroundTaskManager.resetAllEfficiencyResources();
} catch (error) {
    console.error(`resetAllEfficiencyResources failed. code is ${error.code} message is ${error.message}`);
}
```

## DelaySuspendInfo

G
Gloria 已提交
566
Defines the information about the transient task.
567 568 569 570 571

**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask

| Name            | Type    | Mandatory  | Description                                      |
| --------------- | ------ | ---- | ---------------------------------------- |
G
Gloria 已提交
572 573
| requestId       | number | Yes   | Request ID of the transient task.                              |
| actualDelayTime | number | Yes   | Actual duration of the transient task that the application requests, in milliseconds.<br>The maximum duration of a transient task is 3 minutes in normal cases. In the case of a [low battery](js-apis-battery-info.md), the maximum duration is decreased to 1 minute.|
574 575 576

## BackgroundMode

G
Gloria 已提交
577 578
Enumerates the continuous task modes.

579 580 581 582 583 584 585 586 587 588
**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask

| Name                    | Value | Description                   |
| ----------------------- | ---- | --------------------- |
| DATA_TRANSFER           | 1    | Data transfer.                 |
| AUDIO_PLAYBACK          | 2    | Audio playback.                 |
| AUDIO_RECORDING         | 3    | Audio recording.                   |
| LOCATION                | 4    | Positioning and navigation.                 |
| BLUETOOTH_INTERACTION   | 5    | Bluetooth-related task.                 |
| MULTI_DEVICE_CONNECTION | 6    | Multi-device connection.                |
G
Gloria 已提交
589 590 591
| WIFI_INTERACTION        | 7    | WLAN-related.<br>**System API**: This is a system API.|
| VOIP                    | 8    |Audio and video calls.<br>**System API**: This is a system API.|
| TASK_KEEPING            | 9    | Computing task (for specific devices only).       |
592 593 594 595 596 597 598 599 600 601 602 603

## EfficiencyResourcesRequest

Describes the parameters for requesting efficiency resources.

**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply

**System API**: This is a system API.

| Name            | Type    | Mandatory  | Description                                      |
| --------------- | ------ | ---- | ---------------------------------------- |
| resourceTypes   | number  | Yes   | Type of the resource to request.                              |
G
Gloria 已提交
604
| isApply         | boolean | Yes   | Whether the request is used to apply for resources.<br>The value **true** means that the request is used to apply for resources, and **false** means that the request is used to release resources.|
605
| timeOut         | number  | Yes   | Duration for which the resource will be used, in milliseconds.               |
G
Gloria 已提交
606 607
| isPersist       | boolean | No   | Whether the resource is permanently held. The default value is **false**.<br>The value **true** means that the resource is permanently held, and **false** means the resource is held within a given period of time.|
| isProcess       | boolean | No   | Whether the request is initiated by a process. The default value is **false**.<br>The value **true** means that the request is initiated by a process, and **false** means that the request is initiated by an application.        |
608 609 610 611 612 613 614 615 616 617
| reason          | string  | Yes   | Reason for requesting the resource.               |

## ResourceType

Enumerates the efficiency resource types.

**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply

**System API**: This is a system API.

618 619
| Name                    | Value | Description                   |
| ----------------------- | ---- | --------------------- |
G
Gloria 已提交
620 621 622 623 624 625 626
| CPU                     | 1    | CPU resource. Such type of resource prevents an application from being suspended.            |
| COMMON_EVENT            | 2    | Common event resource. Such type of resource ensures that an application in the suspended state can receive common events.|
| TIMER                   | 4    | Timer resource. Such type of resource ensures that an application in the suspended state can be woken up by system timers.|
| WORK_SCHEDULER          | 8    | Deferred task resource. Such type of resource provides a loose control policy for an application.|
| BLUETOOTH               | 16   | Bluetooth resource. Such type of resource ensures that an application in the suspended state can be woken up by Bluetooth-related events.|
| GPS                     | 32   | GPS resource. Such type of resource ensures that an application in the suspended state can be woken up by GPS-related events.|
| AUDIO                   | 64   | Audio resource. Such type of resource prevents an application from being suspended when the application has an audio being played.|
627 628
| RUNNING_LOCK<sup>10+</sup> | 128 | RUNNING_LOCK resources are not proxied when the application is suspended.|
| SENSOR<sup>10+</sup> | 256 | Sensor callbacks are not intercepted.|