• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.resourceschedule.backgroundTaskManager (Background Task Management)
2
3The **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**
6>
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## Modules to Import
11
12```ts
13import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
14```
15
16## backgroundTaskManager.requestSuspendDelay
17
18requestSuspendDelay(reason: string, callback: Callback<void>): DelaySuspendInfo
19
20Requests a transient task.
21
22>  **NOTE**
23>
24> 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**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
27
28**Parameters**
29
30| Name     | Type                  | Mandatory  | Description                            |
31| -------- | -------------------- | ---- | ------------------------------ |
32| reason   | string               | Yes   | Reason for requesting the transient task.                    |
33| 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**Return value**
36
37| Type                                   | Description       |
38| ------------------------------------- | --------- |
39| [DelaySuspendInfo](#delaysuspendinfo) | Information about the transient task.|
40
41**Error codes**
42
43For details about the error codes, see [backgroundTaskManager Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).
44
45| ID | Error Message            |
46| ---- | --------------------- |
47| 9800001 | Memory operation failed. |
48| 9800002 | Parcel operation failed. |
49| 9800003 | Inner transact failed. | |
50| 9800004 | System service operation failed. |
51| 9900001 | Caller information verification failed. |
52| 9900002 | Background task verification failed. |
53
54**Example**
55
56```ts
57import { BusinessError } from '@ohos.base';
58
59let myReason = 'test requestSuspendDelay';
60try {
61    let delayInfo = backgroundTaskManager.requestSuspendDelay(myReason, () => {
62        console.info("Request suspension delay will time out.");
63    })
64    let id = delayInfo.requestId;
65    let time = delayInfo.actualDelayTime;
66    console.info("The requestId is: " + id);
67    console.info("The actualDelayTime is: " + time);
68} catch (error) {
69    console.error(`requestSuspendDelay failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
70}
71```
72
73
74## backgroundTaskManager.getRemainingDelayTime
75
76getRemainingDelayTime(requestId: number, callback: AsyncCallback<number>): void
77
78Obtains the remaining time of a transient task. This API uses an asynchronous callback to return the result.
79
80**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
81
82**Parameters**
83
84| Name      | Type                         | Mandatory  | Description                                      |
85| --------- | --------------------------- | ---- | ---------------------------------------- |
86| requestId | number                      | Yes   | Request ID of the transient task.                              |
87| callback  | AsyncCallback<number> | Yes   | Callback used to return the remaining time, in milliseconds.|
88
89**Error codes**
90
91For details about the error codes, see [backgroundTaskManager Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).
92
93| ID | Error Message            |
94| ---- | --------------------- |
95| 9800001 | Memory operation failed. |
96| 9800002 | Parcel operation failed. |
97| 9800003 | Inner transact failed.  |
98| 9800004 | System service operation failed. |
99| 9900001 | Caller information verification failed. |
100| 9900002 | Background task verification failed. |
101
102
103**Example**
104
105```ts
106import { BusinessError } from '@ohos.base';
107
108let id = 1;
109backgroundTaskManager.getRemainingDelayTime(id, (error: BusinessError, res: number) => {
110    if(error) {
111        console.error(`callback => Operation getRemainingDelayTime failed. code is ${error.code} message is ${error.message}`);
112    } else {
113        console.log('callback => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res));
114    }
115})
116```
117
118
119## backgroundTaskManager.getRemainingDelayTime
120
121getRemainingDelayTime(requestId: number): Promise<number>
122
123Obtains the remaining time of a transient task. This API uses a promise to return the result.
124
125**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
126
127**Parameters**
128
129| Name      | Type    | Mandatory  | Description        |
130| --------- | ------ | ---- | ---------- |
131| requestId | number | Yes   | Request ID of the transient task.|
132
133**Return value**
134
135| Type                   | Description                                      |
136| --------------------- | ---------------------------------------- |
137| Promise<number> | Promise used to return the remaining time, in milliseconds.|
138
139**Error codes**
140
141For details about the error codes, see [backgroundTaskManager Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).
142
143| ID | Error Message            |
144| ---- | --------------------- |
145| 9800001 | Memory operation failed. |
146| 9800002 | Parcel operation failed. |
147| 9800003 | Inner transact failed. | |
148| 9800004 | System service operation failed. |
149| 9900001 | Caller information verification failed. |
150| 9900002 | Background task verification failed. |
151
152**Example**
153
154```ts
155import { BusinessError } from '@ohos.base';
156
157let id = 1;
158backgroundTaskManager.getRemainingDelayTime(id).then((res: number) => {
159    console.log('promise => Operation getRemainingDelayTime succeeded. Data: ' + JSON.stringify(res));
160}).catch((error: BusinessError) => {
161    console.error(`promise => Operation getRemainingDelayTime failed. code is ${error.code} message is ${error.message}`);
162})
163```
164
165
166## backgroundTaskManager.cancelSuspendDelay
167
168cancelSuspendDelay(requestId: number): void
169
170Cancels a transient task.
171
172**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
173
174**Parameters**
175
176| Name      | Type    | Mandatory  | Description        |
177| --------- | ------ | ---- | ---------- |
178| requestId | number | Yes   | Request ID of the transient task.|
179
180**Error codes**
181
182For details about the error codes, see [backgroundTaskManager Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).
183
184| ID | Error Message            |
185| ---- | --------------------- |
186| 9800001 | Memory operation failed. |
187| 9800002 | Parcel operation failed. |
188| 9800003 | Inner transact failed. | |
189| 9800004 | System service operation failed. |
190| 9900001 | Caller information verification failed. |
191| 9900002 | Background task verification failed. |
192
193**Example**
194
195  ```js
196  import { BusinessError } from '@ohos.base';
197
198  let id = 1;
199  try {
200    backgroundTaskManager.cancelSuspendDelay(id);
201  } catch (error) {
202    console.error(`cancelSuspendDelay failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
203  }
204  ```
205
206## backgroundTaskManager.startBackgroundRunning
207
208startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent, callback: AsyncCallback<void>): void
209
210Requests a continuous task. This API uses an asynchronous callback to return the result.
211
212**Required permissions**: ohos.permission.KEEP_BACKGROUND_RUNNING
213
214**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
215
216**Parameters**
217
218| Name      | Type                                | Mandatory  | Description                                      |
219| --------- | ---------------------------------- | ---- | ---------------------------------------- |
220| 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).|
221| bgMode    | [BackgroundMode](#backgroundmode) | Yes   | Continuous task mode.                             |
222| 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.          |
223| 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.   |
224
225**Error codes**
226
227For details about the error codes, see [backgroundTaskManager Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).
228
229| ID | Error Message            |
230| ---- | --------------------- |
231| 9800001 | Memory operation failed. |
232| 9800002 | Parcel operation failed. |
233| 9800003 | Inner transact failed. | |
234| 9800004 | System service operation failed. |
235| 9800005 | Background task verification failed. |
236| 9800006 | Notification verification failed. |
237| 9800007 | Task storage failed. |
238
239**Example**
240
241```js
242import UIAbility from '@ohos.app.ability.UIAbility';
243import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
244import wantAgent, { WantAgent } from '@ohos.app.ability.wantAgent';
245import Want from '@ohos.app.ability.Want';
246import AbilityConstant from '@ohos.app.ability.AbilityConstant';
247import { BusinessError } from '@ohos.base';
248
249function callback(error: BusinessError, data: void) {
250    if (error) {
251        console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
252    } else {
253        console.info("Operation startBackgroundRunning succeeded");
254    }
255}
256
257export default class EntryAbility extends UIAbility {
258    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
259        let wantAgentInfo: wantAgent.WantAgentInfo = {
260            // List of operations to be executed after the notification is clicked.
261            wants: [
262                {
263                    bundleName: "com.example.myapplication",
264                    abilityName: "EntryAbility"
265                }
266            ],
267            // Type of the operation to perform after the notification is clicked.
268            operationType: wantAgent.OperationType.START_ABILITY,
269            // Custom request code.
270            requestCode: 0,
271            // Execution attribute of the operation to perform after the notification is clicked.
272            wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
273        };
274
275        try {
276            // Obtain the WantAgent object by using the getWantAgent API of the wantAgent module.
277            wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj: WantAgent) => {
278                try {
279                    backgroundTaskManager.startBackgroundRunning(this.context,
280                        backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj, callback)
281                } catch (error) {
282                    console.error(`Operation startBackgroundRunning failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
283                }
284            });
285        } catch (error) {
286            console.error(`Operation getWantAgent failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
287        }
288    }
289};
290```
291
292## backgroundTaskManager.startBackgroundRunning
293
294startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent): Promise&lt;void&gt;
295
296Requests a continuous task. This API uses a promise to return the result.
297
298**Required permissions**: ohos.permission.KEEP_BACKGROUND_RUNNING
299
300**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
301
302**Parameters**
303
304| Name      | Type                                | Mandatory  | Description                                      |
305| --------- | ---------------------------------- | ---- | ---------------------------------------- |
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).|
307| bgMode    | [BackgroundMode](#backgroundmode) | Yes   | Continuous task mode.                             |
308| 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**Return value**
311
312| Type            | Description              |
313| -------------- | ---------------- |
314| Promise\<void> | Promise that returns no value.|
315
316**Error codes**
317
318For details about the error codes, see [backgroundTaskManager Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).
319
320| ID | Error Message            |
321| ---- | --------------------- |
322| 9800001 | Memory operation failed. |
323| 9800002 | Parcel operation failed. |
324| 9800003 | Inner transact failed. | |
325| 9800004 | System service operation failed. |
326| 9800005 | Background task verification failed. |
327| 9800006 | Notification verification failed. |
328| 9800007 | Task storage failed. |
329
330**Example**
331
332```js
333import UIAbility from '@ohos.app.ability.UIAbility';
334import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
335import wantAgent, { WantAgent } from '@ohos.app.ability.wantAgent';
336import Want from '@ohos.app.ability.Want';
337import AbilityConstant from '@ohos.app.ability.AbilityConstant';
338import { BusinessError } from '@ohos.base';
339
340export default class EntryAbility extends UIAbility {
341    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
342        let wantAgentInfo: wantAgent.WantAgentInfo = {
343            // List of operations to be executed after the notification is clicked.
344            wants: [
345                {
346                    bundleName: "com.example.myapplication",
347                    abilityName: "EntryAbility"
348                }
349            ],
350            // Type of the operation to perform after the notification is clicked.
351            operationType: wantAgent.OperationType.START_ABILITY,
352            // Custom request code.
353            requestCode: 0,
354            // Execution attribute of the operation to perform after the notification is clicked.
355            wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
356        };
357
358        try {
359            // Obtain the WantAgent object by using the getWantAgent API of the wantAgent module.
360            wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj: WantAgent) => {
361                try {
362                    backgroundTaskManager.startBackgroundRunning(this.context,
363                        backgroundTaskManager.BackgroundMode.LOCATION, wantAgentObj).then(() => {
364                        console.info("Operation startBackgroundRunning succeeded");
365                    }).catch((error: BusinessError) => {
366                        console.error(`Operation startBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
367                    });
368                } catch (error) {
369                    console.error(`Operation startBackgroundRunning failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
370                }
371            });
372        } catch (error) {
373            console.error(`Operation getWantAgent failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
374        }
375    }
376};
377```
378
379## backgroundTaskManager.stopBackgroundRunning
380
381stopBackgroundRunning(context: Context, callback: AsyncCallback&lt;void&gt;): void
382
383Cancels a continuous task. This API uses an asynchronous callback to return the result.
384
385**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
386
387**Parameters**
388
389| Name     | Type                       | Mandatory  | Description                                      |
390| -------- | ------------------------- | ---- | ---------------------------------------- |
391| 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).|
392| 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.|
393
394**Error codes**
395
396For details about the error codes, see [backgroundTaskManager Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).
397
398| ID | Error Message            |
399| ---- | --------------------- |
400| 9800001 | Memory operation failed. |
401| 9800002 | Parcel operation failed. |
402| 9800003 | Inner transact failed. | |
403| 9800004 | System service operation failed. |
404| 9800005 | Background task verification failed. |
405| 9800006 | Notification verification failed. |
406| 9800007 | Task storage failed. |
407
408**Example**
409
410```js
411import UIAbility from '@ohos.app.ability.UIAbility';
412import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
413import Want from '@ohos.app.ability.Want';
414import AbilityConstant from '@ohos.app.ability.AbilityConstant';
415import { BusinessError } from '@ohos.base';
416
417function callback(error: BusinessError, data: void) {
418    if (error) {
419        console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
420    } else {
421        console.info("Operation stopBackgroundRunning succeeded");
422    }
423}
424
425export default class EntryAbility extends UIAbility {
426    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
427        try {
428            backgroundTaskManager.stopBackgroundRunning(this.context, callback);
429        } catch (error) {
430            console.error(`Operation stopBackgroundRunning failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
431        }
432    }
433};
434```
435
436## backgroundTaskManager.stopBackgroundRunning
437
438stopBackgroundRunning(context: Context): Promise&lt;void&gt;
439
440Cancels a continuous task. This API uses a promise to return the result.
441
442**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
443
444**Parameters**
445
446| Name    | Type     | Mandatory  | Description                                      |
447| ------- | ------- | ---- | ---------------------------------------- |
448| 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).|
449
450**Return value**
451
452| Type            | Description              |
453| -------------- | ---------------- |
454| Promise\<void> | Promise that returns no value.|
455
456**Error codes**
457
458For details about the error codes, see [backgroundTaskManager Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).
459
460| ID | Error Message            |
461| ---- | --------------------- |
462| 9800001 | Memory operation failed. |
463| 9800002 | Parcel operation failed. |
464| 9800003 | Inner transact failed. | |
465| 9800004 | System service operation failed. |
466| 9800005 | Background task verification failed. |
467| 9800006 | Notification verification failed. |
468| 9800007 | Task storage failed. |
469
470**Example**
471
472```js
473import UIAbility from '@ohos.app.ability.UIAbility';
474import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager';
475import Want from '@ohos.app.ability.Want';
476import AbilityConstant from '@ohos.app.ability.AbilityConstant';
477import { BusinessError } from '@ohos.base';
478
479export default class EntryAbility extends UIAbility {
480    onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
481        try {
482            backgroundTaskManager.stopBackgroundRunning(this.context).then(() => {
483                console.info("Operation stopBackgroundRunning succeeded");
484            }).catch((error: BusinessError) => {
485                console.error(`Operation stopBackgroundRunning failed. code is ${error.code} message is ${error.message}`);
486            });
487        } catch (error) {
488            console.error(`Operation stopBackgroundRunning failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
489        }
490    }
491};
492```
493
494## backgroundTaskManager.applyEfficiencyResources
495
496applyEfficiencyResources(request: EfficiencyResourcesRequest): void
497
498Requests efficiency resources.
499
500**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply
501
502**System API**: This is a system API.
503
504**Parameters**
505
506| Name    | Type     | Mandatory  | Description                                      |
507| ------- | ------- | ---- | ---------------------------------------- |
508| request | [EfficiencyResourcesRequest](#efficiencyresourcesrequest) | Yes   | Necessary information carried in the request, including the resource type and timeout interval.|
509
510
511**Error codes**
512
513For details about the error codes, see [backgroundTaskManager Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).
514
515| ID | Error Message            |
516| ---- | --------------------- |
517| 9800001 | Memory operation failed. |
518| 9800002 | Parcel operation failed. |
519| 9800003 | Inner transact failed. | |
520| 9800004 | System service operation failed. |
521| 18700001 | Caller information verification failed. |
522
523**Example**
524
525```js
526import { BusinessError } from '@ohos.base';
527
528let request: backgroundTaskManager.EfficiencyResourcesRequest = {
529    resourceTypes: backgroundTaskManager.ResourceType.CPU,
530    isApply: true,
531    timeOut: 0,
532    reason: "apply",
533    isPersist: true,
534    isProcess: false,
535};
536try {
537    backgroundTaskManager.applyEfficiencyResources(request);
538    console.info("applyEfficiencyResources success. ");
539} catch (error) {
540    console.error(`applyEfficiencyResources failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
541}
542```
543
544## backgroundTaskManager.resetAllEfficiencyResources
545
546resetAllEfficiencyResources(): void
547
548Releases all efficiency resources.
549
550**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply
551
552**System API**: This is a system API.
553
554**Error codes**
555
556For details about the error codes, see [backgroundTaskManager Error Codes](../errorcodes/errorcode-backgroundTaskMgr.md).
557
558| ID | Error Message            |
559| ---- | --------------------- |
560| 9800001 | Memory operation failed. |
561| 9800002 | Parcel operation failed. |
562| 9800003 | Inner transact failed. | |
563| 9800004 | System service operation failed. |
564| 18700001 | Caller information verification failed. |
565
566**Example**
567
568```js
569import { BusinessError } from '@ohos.base';
570
571try {
572    backgroundTaskManager.resetAllEfficiencyResources();
573} catch (error) {
574    console.error(`resetAllEfficiencyResources failed. code is ${(error as BusinessError).code} message is ${(error as BusinessError).message}`);
575}
576```
577
578## DelaySuspendInfo
579
580Defines the information about the transient task.
581
582**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
583
584| Name            | Type    | Mandatory  | Description                                      |
585| --------------- | ------ | ---- | ---------------------------------------- |
586| requestId       | number | Yes   | Request ID of the transient task.                              |
587| 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.|
588
589## BackgroundMode
590
591Enumerates the continuous task modes.
592
593**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
594
595| Name                    | Value | Description                   |
596| ----------------------- | ---- | --------------------- |
597| DATA_TRANSFER           | 1    | Data transfer.                 |
598| AUDIO_PLAYBACK          | 2    | Audio playback.                 |
599| AUDIO_RECORDING         | 3    | Audio recording.                   |
600| LOCATION                | 4    | Positioning and navigation.                 |
601| BLUETOOTH_INTERACTION   | 5    | Bluetooth-related task.                 |
602| MULTI_DEVICE_CONNECTION | 6    | Multi-device connection.                |
603| WIFI_INTERACTION        | 7    | WLAN-related.<br>**System API**: This is a system API.|
604| VOIP                    | 8    | Audio and video calls.<br>**System API**: This is a system API.|
605| TASK_KEEPING            | 9    | Computing task (for specific devices only).       |
606
607## EfficiencyResourcesRequest
608
609Describes the parameters for requesting efficiency resources.
610
611**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply
612
613**System API**: This is a system API.
614
615| Name            | Type    | Mandatory  | Description                                      |
616| --------------- | ------ | ---- | ---------------------------------------- |
617| resourceTypes   | number  | Yes   | Type of the resource to request.                              |
618| 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.|
619| timeOut         | number  | Yes   | Duration for which the resource will be used, in milliseconds.               |
620| 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.|
621| 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.        |
622| reason          | string  | Yes   | Reason for requesting the resource.               |
623
624## ResourceType
625
626Enumerates the efficiency resource types.
627
628**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply
629
630**System API**: This is a system API.
631
632| Name                    | Value | Description                   |
633| ----------------------- | ---- | --------------------- |
634| CPU                     | 1    | CPU resource. Such type of resource prevents an application from being suspended.            |
635| COMMON_EVENT            | 2    | Common event resource. Such type of resource ensures that an application in the suspended state can receive common events.|
636| TIMER                   | 4    | Timer resource. Such type of resource ensures that an application in the suspended state can be woken up by system timers.|
637| WORK_SCHEDULER          | 8    | Deferred task resource. Such type of resource provides a loose control policy for an application.|
638| BLUETOOTH               | 16   | Bluetooth resource. Such type of resource ensures that an application in the suspended state can be woken up by Bluetooth-related events.|
639| GPS                     | 32   | GPS resource. Such type of resource ensures that an application in the suspended state can be woken up by GPS-related events.|
640| AUDIO                   | 64   | Audio resource. Such type of resource prevents an application from being suspended when the application has an audio being played.|
641| RUNNING_LOCK<sup>10+</sup> | 128 | RUNNING_LOCK resources are not proxied when the application is suspended.|
642| SENSOR<sup>10+</sup> | 256 | Sensor callbacks are not intercepted.|
643