提交 7a40b8c1 编写于 作者: G Gloria

Update docs against 21875+22433

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 71938187
# @ohos.WorkSchedulerExtensionAbility (Deferred Task Scheduling Callbacks) # @ohos.WorkSchedulerExtensionAbility (Deferred Task Scheduling Callbacks)
The **WorkSchedulerExtensionAbility** module provides callbacks for deferred task scheduling. The **WorkSchedulerExtensionAbility** module provides callbacks for deferred task scheduling. You can override the APIs provided by this module. When a deferred task is triggered, the system calls back the application through the APIs and processes the task logic in the callback.
When developing an application, you can override the APIs of this module and add your own task logic to the APIs.
> **NOTE** > **NOTE**
> >
> - 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. > - 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.
>
> - The APIs of this module can be used only in the stage model. > - The APIs of this module can be used only in the stage model.
## Modules to Import ## Modules to Import
```ts ```ts
...@@ -36,7 +34,7 @@ Called when the system starts scheduling the deferred task. ...@@ -36,7 +34,7 @@ Called when the system starts scheduling the deferred task.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ---------------------------------------- | ---- | -------------- | | ---- | ---------------------------------------- | ---- | -------------- |
| work | [workScheduler.WorkInfo](js-apis-resourceschedule-workScheduler.md#workinfo) | Yes | Target task.| | work | [workScheduler.WorkInfo](js-apis-resourceschedule-workScheduler.md#workinfo) | Yes | Deferred task that starts.|
**Example** **Example**
...@@ -60,7 +58,7 @@ Called when the system stops scheduling the deferred task. ...@@ -60,7 +58,7 @@ Called when the system stops scheduling the deferred task.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ---------------------------------------- | ---- | -------------- | | ---- | ---------------------------------------- | ---- | -------------- |
| work | [workScheduler.WorkInfo](js-apis-resourceschedule-workScheduler.md#workinfo) | Yes | Target task.| | work | [workScheduler.WorkInfo](js-apis-resourceschedule-workScheduler.md#workinfo) | Yes | Deferred task that stops.|
**Example** **Example**
......
# @ohos.distributedMissionManager (Distributed Mission Management) # @ohos.distributedMissionManager (Distributed Mission Management)
The **distributedMissionManager** module implements system mission management across devices. You can use the APIs provided by this module to register or deregister a mission status listener, start or stop synchronizing a remote mission list, and continue a mission on a remote device. The **distributedMissionManager** module implements mission management across devices. You can use the APIs provided by this module to register or deregister a mission status listener, start or stop synchronizing a remote mission list, and continue a mission on a remote device by mission ID or bundle name.
> **NOTE** > **NOTE**
> >
...@@ -14,7 +14,6 @@ The **distributedMissionManager** module implements system mission management ac ...@@ -14,7 +14,6 @@ The **distributedMissionManager** module implements system mission management ac
import distributedMissionManager from '@ohos.distributedMissionManager' import distributedMissionManager from '@ohos.distributedMissionManager'
``` ```
## distributedMissionManager.registerMissionListener ## distributedMissionManager.registerMissionListener
registerMissionListener(parameter: MissionDeviceInfo, options: MissionCallback, callback: AsyncCallback&lt;void&gt;): void; registerMissionListener(parameter: MissionDeviceInfo, options: MissionCallback, callback: AsyncCallback&lt;void&gt;): void;
...@@ -30,8 +29,8 @@ Registers a mission status listener. This API uses an asynchronous callback to r ...@@ -30,8 +29,8 @@ Registers a mission status listener. This API uses an asynchronous callback to r
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | --------------------------------------- | ---- | --------- | | --------- | --------------------------------------- | ---- | --------- |
| parameter | [MissionDeviceInfo](#missiondeviceinfo) | Yes | Information about the device to listen for.| | parameter | [MissionDeviceInfo](#missiondeviceinfo) | Yes | Information about the device to listen for.|
| options | [MissionCallback](#missioncallback) | Yes | Callback to register. | | options | [MissionCallback](#missioncallback) | Yes | Callback to register.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. If the listener is registered, **err** is **undefined**. Otherwise, **err** is an error object.|
**Example** **Example**
...@@ -80,14 +79,14 @@ Registers a mission status listener. This API uses a promise to return the resul ...@@ -80,14 +79,14 @@ Registers a mission status listener. This API uses a promise to return the resul
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------- | | --------- | ---------------------------------------- | ---- | -------- |
| parameter | [MissionDeviceInfo](#missiondeviceinfo) | Yes | Information about the device to listen for. | | parameter | [MissionDeviceInfo](#missiondeviceinfo) | Yes | Information about the device to listen for. |
| options | <a href="#missioncallback">MissionCallback</a> | Yes | Callback to register.| | options | <a href="#missioncallback">MissionCallback</a> | Yes | Callback to register.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------- | | ------------------- | ---------------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -123,7 +122,6 @@ Registers a mission status listener. This API uses a promise to return the resul ...@@ -123,7 +122,6 @@ Registers a mission status listener. This API uses a promise to return the resul
} }
``` ```
## distributedMissionManager.unRegisterMissionListener ## distributedMissionManager.unRegisterMissionListener
unRegisterMissionListener(parameter: MissionDeviceInfo, callback: AsyncCallback&lt;void&gt;): void; unRegisterMissionListener(parameter: MissionDeviceInfo, callback: AsyncCallback&lt;void&gt;): void;
...@@ -138,8 +136,8 @@ Deregisters a mission status listener. This API uses an asynchronous callback to ...@@ -138,8 +136,8 @@ Deregisters a mission status listener. This API uses an asynchronous callback to
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | --------------------------------------- | ---- | --------- | | --------- | --------------------------------------- | ---- | --------- |
| parameter | [MissionDeviceInfo](#missiondeviceinfo) | Yes | Information about the device to listen for. | | parameter | [MissionDeviceInfo](#missiondeviceinfo) | Yes | Information about the device to listen for. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. If the listener is deregistered, **err** is **undefined**. Otherwise, **err** is an error object.|
**Example** **Example**
...@@ -159,7 +157,6 @@ Deregisters a mission status listener. This API uses an asynchronous callback to ...@@ -159,7 +157,6 @@ Deregisters a mission status listener. This API uses an asynchronous callback to
} }
``` ```
## distributedMissionManager.unRegisterMissionListener ## distributedMissionManager.unRegisterMissionListener
unRegisterMissionListener(parameter: MissionDeviceInfo): Promise&lt;void&gt; unRegisterMissionListener(parameter: MissionDeviceInfo): Promise&lt;void&gt;
...@@ -180,7 +177,7 @@ Deregisters a mission status listener. This API uses a promise to return the res ...@@ -180,7 +177,7 @@ Deregisters a mission status listener. This API uses a promise to return the res
| Type | Description | | Type | Description |
| ------------------- | ---------------- | | ------------------- | ---------------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; |Promise that returns no value.|
**Example** **Example**
...@@ -215,7 +212,7 @@ Starts to synchronize the remote mission list. This API uses an asynchronous cal ...@@ -215,7 +212,7 @@ Starts to synchronize the remote mission list. This API uses an asynchronous cal
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ------------------------------------- | ---- | --------- | | --------- | ------------------------------------- | ---- | --------- |
| parameter | [MissionParameter](#missionparameter) | Yes | Parameters required for synchronization. | | parameter | [MissionParameter](#missionparameter) | Yes | Parameters required for synchronization. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. If the synchronization is started, **err** is **undefined**. Otherwise, **err** is an error object.|
**Example** **Example**
...@@ -257,7 +254,7 @@ Starts to synchronize the remote mission list. This API uses a promise to return ...@@ -257,7 +254,7 @@ Starts to synchronize the remote mission list. This API uses a promise to return
| Type | Description | | Type | Description |
| ------------------- | ---------------- | | ------------------- | ---------------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -294,7 +291,7 @@ Stops synchronizing the remote mission list. This API uses an asynchronous callb ...@@ -294,7 +291,7 @@ Stops synchronizing the remote mission list. This API uses an asynchronous callb
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | --------------------------------------- | ---- | --------- | | --------- | --------------------------------------- | ---- | --------- |
| parameter | [MissionDeviceInfo](#missiondeviceinfo) | Yes | Parameters required for synchronization. | | parameter | [MissionDeviceInfo](#missiondeviceinfo) | Yes | Parameters required for synchronization. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. If the synchronization is stopped, **err** is **undefined**. Otherwise, **err** is an error object.|
**Example** **Example**
...@@ -334,7 +331,7 @@ Stops synchronizing the remote mission list. This API uses a promise to return t ...@@ -334,7 +331,7 @@ Stops synchronizing the remote mission list. This API uses a promise to return t
| Type | Description | | Type | Description |
| ------------------- | ---------------- | | ------------------- | ---------------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -358,7 +355,7 @@ Stops synchronizing the remote mission list. This API uses a promise to return t ...@@ -358,7 +355,7 @@ Stops synchronizing the remote mission list. This API uses a promise to return t
continueMission(parameter: ContinueDeviceInfo, options: ContinueCallback, callback: AsyncCallback&lt;void&gt;): void; continueMission(parameter: ContinueDeviceInfo, options: ContinueCallback, callback: AsyncCallback&lt;void&gt;): void;
Continues a mission on a remote device. This API uses an asynchronous callback to return the result. Continues a mission on a remote device, with the mission ID specified. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_MISSIONS and ohos.permission.DISTRIBUTED_DATASYNC **Required permissions**: ohos.permission.MANAGE_MISSIONS and ohos.permission.DISTRIBUTED_DATASYNC
...@@ -370,7 +367,7 @@ Continues a mission on a remote device. This API uses an asynchronous callback t ...@@ -370,7 +367,7 @@ Continues a mission on a remote device. This API uses an asynchronous callback t
| --------- | --------------------------------------- | ---- | ----- | | --------- | --------------------------------------- | ---- | ----- |
| parameter | [ContinueDeviceInfo](js-apis-inner-application-continueDeviceInfo.md) | Yes | Parameters required for mission continuation.| | parameter | [ContinueDeviceInfo](js-apis-inner-application-continueDeviceInfo.md) | Yes | Parameters required for mission continuation.|
| options | [ContinueCallback](js-apis-inner-application-continueCallback.md) | Yes | Callback invoked when the mission continuation is complete.| | options | [ContinueCallback](js-apis-inner-application-continueCallback.md) | Yes | Callback invoked when the mission continuation is complete.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. If the mission is continued, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes** **Error codes**
...@@ -416,7 +413,7 @@ For details about the error codes, see [Distributed Scheduler Error Codes](../er ...@@ -416,7 +413,7 @@ For details about the error codes, see [Distributed Scheduler Error Codes](../er
continueMission(parameter: ContinueDeviceInfo, options: ContinueCallback): Promise&lt;void&gt; continueMission(parameter: ContinueDeviceInfo, options: ContinueCallback): Promise&lt;void&gt;
Continues a mission on a remote device. This API uses a promise to return the result. Continues a mission on a remote device, with the mission ID specified. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MANAGE_MISSIONS and ohos.permission.DISTRIBUTED_DATASYNC **Required permissions**: ohos.permission.MANAGE_MISSIONS and ohos.permission.DISTRIBUTED_DATASYNC
...@@ -433,7 +430,7 @@ Continues a mission on a remote device. This API uses a promise to return the re ...@@ -433,7 +430,7 @@ Continues a mission on a remote device. This API uses a promise to return the re
| Type | Description | | Type | Description |
| ------------------- | ---------------- | | ------------------- | ---------------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; |Promise that returns no value.|
**Error codes** **Error codes**
...@@ -490,7 +487,7 @@ Continues a mission on a remote device, with the bundle name specified. This API ...@@ -490,7 +487,7 @@ Continues a mission on a remote device, with the bundle name specified. This API
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | --------------------------------------- | ---- | ----- | | --------- | --------------------------------------- | ---- | ----- |
| parameter | [ContinueMissionInfo](./js-apis-inner-application-continueMissionInfo.md) | Yes | Parameters required for mission continuation.| | parameter | [ContinueMissionInfo](./js-apis-inner-application-continueMissionInfo.md) | Yes | Parameters required for mission continuation.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the mission continuation is complete.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. If the mission is continued, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes** **Error codes**
...@@ -546,7 +543,7 @@ Continues a mission on a remote device, with the bundle name specified. This API ...@@ -546,7 +543,7 @@ Continues a mission on a remote device, with the bundle name specified. This API
| Type | Description | | Type | Description |
| ------------------- | ---------------- | | ------------------- | ---------------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise that returns no value.|
**Error codes** **Error codes**
...@@ -586,7 +583,7 @@ For details about the error codes, see [Distributed Scheduler Error Codes](../er ...@@ -586,7 +583,7 @@ For details about the error codes, see [Distributed Scheduler Error Codes](../er
on(type: 'continueStateChange', callback: Callback&lt;{ state: ContinueState, info: ContinuableInfo }&gt;): void on(type: 'continueStateChange', callback: Callback&lt;{ state: ContinueState, info: ContinuableInfo }&gt;): void
Registers a listener for the mission continuation state of the current application. Subscribes to continuation state change events of the current mission.
**Required permissions**: ohos.permission.MANAGE_MISSIONS **Required permissions**: ohos.permission.MANAGE_MISSIONS
...@@ -596,8 +593,8 @@ Registers a listener for the mission continuation state of the current applicati ...@@ -596,8 +593,8 @@ Registers a listener for the mission continuation state of the current applicati
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------- | | --------- | ---------------------------------------- | ---- | -------- |
| type | string | Yes | Type of the listener. The value is fixed at **'continueStateChange'**. | | type | string | Yes | Event type. The value **'continueStateChange'** indicates the continuation state change event of the current mission. |
| callback | Callback&lt;{&nbsp;state:&nbsp;[ContinueState](#continuestate10),&nbsp;info:&nbsp;[ContinuableInfo](./js-apis-inner-application-continuableInfo.md)&nbsp;}&gt; | Yes | Callback used to return the mission continuation state and information. | | callback | Callback&lt;{&nbsp;state:&nbsp;[ContinueState](#continuestate10),&nbsp;info:&nbsp;[ContinuableInfo](./js-apis-inner-application-continuableInfo.md)&nbsp;}&gt; | Yes | Callback used to return the continuation state and information of the current mission. |
**Example** **Example**
...@@ -615,7 +612,7 @@ Registers a listener for the mission continuation state of the current applicati ...@@ -615,7 +612,7 @@ Registers a listener for the mission continuation state of the current applicati
off(type: 'continueStateChange', callback?: Callback&lt;{ state: ContinueState, info: ContinuableInfo }&gt;): void off(type: 'continueStateChange', callback?: Callback&lt;{ state: ContinueState, info: ContinuableInfo }&gt;): void
Deregisters a listener for the mission continuation state of the current application. Unsubscribes from continuation state change events of the current mission.
**Required permissions**: ohos.permission.MANAGE_MISSIONS **Required permissions**: ohos.permission.MANAGE_MISSIONS
...@@ -625,8 +622,8 @@ Deregisters a listener for the mission continuation state of the current applica ...@@ -625,8 +622,8 @@ Deregisters a listener for the mission continuation state of the current applica
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ---------------------------------------- | ---- | -------- | | --------- | ---------------------------------------- | ---- | -------- |
| type | string | Yes | Type of the listener. The value is fixed at **'continueStateChange'**. | | type | string | Yes | Event type. The value **'continueStateChange'** indicates the continuation state change event of the current mission. |
| callback | Callback&lt;{&nbsp;state:&nbsp;[ContinueState](#continuestate10),&nbsp;info:&nbsp;[ContinuableInfo](./js-apis-inner-application-continuableInfo.md)&nbsp;}&gt; | No | Callback used for the listener to be deregistered. | | callback | Callback&lt;{&nbsp;state:&nbsp;[ContinueState](#continuestate10),&nbsp;info:&nbsp;[ContinuableInfo](./js-apis-inner-application-continuableInfo.md)&nbsp;}&gt; | No | Callback used to return the continuation state and information of the current mission.<br>If the callback is unspecified, all subscriptions to the specified event are canceled. |
**Example** **Example**
...@@ -688,5 +685,5 @@ Enumerates the mission continuation states. ...@@ -688,5 +685,5 @@ Enumerates the mission continuation states.
| Name | Value | Description | | Name | Value | Description |
| ------------- | --------- | ------------------------------------------------------------ | | ------------- | --------- | ------------------------------------------------------------ |
| ACTIVE | 0 | Mission continuation is activated for the current application. | | ACTIVE | 0 | Continuation is activated for the current mission. |
| INACTIVE | 1 | Mission continuation is not activated for the current application. | | INACTIVE | 1 | Continuation is not activated for the current mission. |
# @ohos.reminderAgentManager (reminderAgentManager) # @ohos.reminderAgentManager (Agent-Powered Reminders)
The **reminderAgentManager** module provides APIs for publishing scheduled reminders through the reminder agent. The **reminderAgentManager** module provides APIs related to agent-powered reminders. When your application is frozen or exits, the timing and notification functions of your application will be taken over by a system service running in the background. You can use the APIs to create scheduled reminders for countdown timers, calendar events, and alarm clocks.
You can use the APIs to create scheduled reminders for countdown timers, calendar events, and alarm clocks. When the created reminders are published, the timing and pop-up notification functions of your application will be taken over by the reminder agent in the background when your application is frozen or exits.
> **NOTE** > **NOTE**
> >
...@@ -15,12 +13,15 @@ You can use the APIs to create scheduled reminders for countdown timers, calenda ...@@ -15,12 +13,15 @@ You can use the APIs to create scheduled reminders for countdown timers, calenda
import reminderAgentManager from'@ohos.reminderAgentManager'; import reminderAgentManager from'@ohos.reminderAgentManager';
``` ```
## reminderAgentManager.publishReminder ## reminderAgentManager.publishReminder
publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback\<number>): void publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback\<number>): void
Publishes a reminder through the reminder agent. This API uses an asynchronous callback to return the result. It can be called only when notification is enabled for the application through [Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8). Publishes a reminder. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API can be called only after the [Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8) permission is obtained.
**Required permissions**: ohos.permission.PUBLISH_AGENT_REMINDER **Required permissions**: ohos.permission.PUBLISH_AGENT_REMINDER
...@@ -28,10 +29,10 @@ Publishes a reminder through the reminder agent. This API uses an asynchronous c ...@@ -28,10 +29,10 @@ Publishes a reminder through the reminder agent. This API uses an asynchronous c
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| reminderReq | [ReminderRequest](#reminderrequest) | Yes| Reminder to be published.| | reminderReq | [ReminderRequest](#reminderrequest) | Yes| Request used for publishing the reminder.|
| callback | AsyncCallback\<number> | Yes| Callback used to return the published reminder's ID.| | callback | AsyncCallback\<number> | Yes| Callback used to return the published reminder's ID.|
**Error codes** **Error codes**
...@@ -62,26 +63,29 @@ try { ...@@ -62,26 +63,29 @@ try {
}; };
``` ```
## reminderAgentManager.publishReminder ## reminderAgentManager.publishReminder
publishReminder(reminderReq: ReminderRequest): Promise\<number> publishReminder(reminderReq: ReminderRequest): Promise\<number>
Publishes a reminder through the reminder agent. This API uses a promise to return the result. It can be called only when notification is enabled for the application through [Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8). Publishes a reminder. This API uses a promise to return the result.
> **NOTE**
>
> This API can be called only after the [Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8) permission is obtained.
**Required permissions**: ohos.permission.PUBLISH_AGENT_REMINDER **Required permissions**: ohos.permission.PUBLISH_AGENT_REMINDER
**System capability**: SystemCapability.Notification.ReminderAgent **System capability**: SystemCapability.Notification.ReminderAgent
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| reminderReq | [ReminderRequest](#reminderrequest) | Yes| Reminder to be published.| | reminderReq | [ReminderRequest](#reminderrequest) | Yes| Request used for publishing the reminder.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise\<number> | Promise used to return the published reminder's ID.| | Promise\<number> | Promise used to return the published reminder's ID.|
**Error codes** **Error codes**
...@@ -115,7 +119,7 @@ try { ...@@ -115,7 +119,7 @@ try {
cancelReminder(reminderId: number, callback: AsyncCallback\<void>): void cancelReminder(reminderId: number, callback: AsyncCallback\<void>): void
Cancels the reminder with the specified ID. This API uses an asynchronous callback to return the cancellation result. Cancels a reminder published. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.ReminderAgent **System capability**: SystemCapability.Notification.ReminderAgent
...@@ -124,7 +128,7 @@ Cancels the reminder with the specified ID. This API uses an asynchronous callba ...@@ -124,7 +128,7 @@ Cancels the reminder with the specified ID. This API uses an asynchronous callba
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| reminderId | number | Yes| ID of the reminder to cancel.| | reminderId | number | Yes| ID of the reminder to cancel.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.| | callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the reminder is canceled, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes** **Error codes**
...@@ -151,12 +155,11 @@ try { ...@@ -151,12 +155,11 @@ try {
}; };
``` ```
## reminderAgentManager.cancelReminder ## reminderAgentManager.cancelReminder
cancelReminder(reminderId: number): Promise\<void> cancelReminder(reminderId: number): Promise\<void>
Cancels the reminder with the specified ID. This API uses a promise to return the cancellation result. Cancels a reminder published. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.ReminderAgent **System capability**: SystemCapability.Notification.ReminderAgent
...@@ -170,7 +173,7 @@ Cancels the reminder with the specified ID. This API uses a promise to return th ...@@ -170,7 +173,7 @@ Cancels the reminder with the specified ID. This API uses a promise to return th
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise that returns no value.|
**Error codes** **Error codes**
...@@ -199,8 +202,7 @@ try { ...@@ -199,8 +202,7 @@ try {
getValidReminders(callback: AsyncCallback<Array\<ReminderRequest>>): void getValidReminders(callback: AsyncCallback<Array\<ReminderRequest>>): void
Obtains all valid (not yet expired) reminders set by the current application. This API uses an asynchronous callback to return the result.
Obtains all valid (not yet expired) reminders set by the current application. This API uses an asynchronous callback to return the reminders.
**System capability**: SystemCapability.Notification.ReminderAgent **System capability**: SystemCapability.Notification.ReminderAgent
...@@ -208,7 +210,7 @@ Obtains all valid (not yet expired) reminders set by the current application. Th ...@@ -208,7 +210,7 @@ Obtains all valid (not yet expired) reminders set by the current application. Th
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback\<Array\<[ReminderRequest](#reminderrequest)>> | Yes| Asynchronous callback used to return an array of all valid reminders set by the current application.| | callback | AsyncCallback\<Array\<[ReminderRequest](#reminderrequest)>> | Yes| Callback used to return all the valid reminders.|
**Error codes** **Error codes**
...@@ -259,7 +261,7 @@ try { ...@@ -259,7 +261,7 @@ try {
getValidReminders(): Promise\<Array\<ReminderRequest>> getValidReminders(): Promise\<Array\<ReminderRequest>>
Obtains all valid (not yet expired) reminders set by the current application. This API uses a promise to return the reminders. Obtains all valid (not yet expired) reminders set by the current application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.ReminderAgent **System capability**: SystemCapability.Notification.ReminderAgent
...@@ -267,7 +269,7 @@ Obtains all valid (not yet expired) reminders set by the current application. Th ...@@ -267,7 +269,7 @@ Obtains all valid (not yet expired) reminders set by the current application. Th
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise\<Array\<[ReminderRequest](#reminderrequest)>> | Promise used to return an array of all valid reminders set by the current application.| | Promise\<Array\<[ReminderRequest](#reminderrequest)>> | Promise used to return all the valid reminders.|
**Error codes** **Error codes**
...@@ -312,12 +314,11 @@ try { ...@@ -312,12 +314,11 @@ try {
}; };
``` ```
## reminderAgentManager.cancelAllReminders ## reminderAgentManager.cancelAllReminders
cancelAllReminders(callback: AsyncCallback\<void>): void cancelAllReminders(callback: AsyncCallback\<void>): void
Cancels all reminders set by the current application. This API uses an asynchronous callback to return the cancellation result. Cancels all reminders set by the current application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.ReminderAgent **System capability**: SystemCapability.Notification.ReminderAgent
...@@ -325,7 +326,7 @@ Cancels all reminders set by the current application. This API uses an asynchron ...@@ -325,7 +326,7 @@ Cancels all reminders set by the current application. This API uses an asynchron
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.| | callback | AsyncCallback\<void> | Yes| Callback used to return the result. If all the reminders are canceled, **err** is **undefined**. Otherwise, **err** is an error object. |
**Error codes** **Error codes**
...@@ -351,12 +352,11 @@ try { ...@@ -351,12 +352,11 @@ try {
}; };
``` ```
## reminderAgentManager.cancelAllReminders ## reminderAgentManager.cancelAllReminders
cancelAllReminders(): Promise\<void> cancelAllReminders(): Promise\<void>
Cancels all reminders set by the current application. This API uses a promise to return the cancellation result. Cancels all reminders set by the current application. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.ReminderAgent **System capability**: SystemCapability.Notification.ReminderAgent
...@@ -364,7 +364,7 @@ Cancels all reminders set by the current application. This API uses a promise to ...@@ -364,7 +364,7 @@ Cancels all reminders set by the current application. This API uses a promise to
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise that returns no value.|
**Error codes** **Error codes**
...@@ -401,8 +401,8 @@ Adds a notification slot. This API uses an asynchronous callback to return the r ...@@ -401,8 +401,8 @@ Adds a notification slot. This API uses an asynchronous callback to return the r
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| slot | [NotificationSlot](js-apis-notification.md#notificationslot) | Yes| Notification slot, whose type can be set.| | slot | [NotificationSlot](js-apis-notification.md#notificationslot) | Yes| Notification slot. Only the type can be set.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.| | callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the notification slot is added, **err** is **undefined**. Otherwise, **err** is an error object.|
**Example** **Example**
...@@ -438,13 +438,13 @@ Adds a notification slot. This API uses a promise to return the result. ...@@ -438,13 +438,13 @@ Adds a notification slot. This API uses a promise to return the result.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| slot | [NotificationSlot](js-apis-notification.md#notificationslot) | Yes| Notification slot, whose type can be set.| | slot | [NotificationSlot](js-apis-notification.md#notificationslot) | Yes| Notification slot. Only the type can be set.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise that returns no value.|
**Example** **Example**
...@@ -470,7 +470,7 @@ try { ...@@ -470,7 +470,7 @@ try {
removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback\<void>): void removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback\<void>): void
Removes a notification slot of a specified type. This API uses an asynchronous callback to return the result. Removes a notification slot. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Notification.ReminderAgent **System capability**: SystemCapability.Notification.ReminderAgent
...@@ -479,7 +479,7 @@ Removes a notification slot of a specified type. This API uses an asynchronous c ...@@ -479,7 +479,7 @@ Removes a notification slot of a specified type. This API uses an asynchronous c
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| slotType | [notification.SlotType](js-apis-notification.md#slottype) | Yes| Type of the notification slot to remove.| | slotType | [notification.SlotType](js-apis-notification.md#slottype) | Yes| Type of the notification slot to remove.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result.| | callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the notification slot is removed, **err** is **undefined**. Otherwise, **err** is an error object.|
**Example** **Example**
...@@ -504,7 +504,7 @@ try { ...@@ -504,7 +504,7 @@ try {
removeNotificationSlot(slotType: notification.SlotType): Promise\<void> removeNotificationSlot(slotType: notification.SlotType): Promise\<void>
Removes a notification slot of a specified type. This API uses a promise to return the result. Removes a notification slot. This API uses a promise to return the result.
**System capability**: SystemCapability.Notification.ReminderAgent **System capability**: SystemCapability.Notification.ReminderAgent
...@@ -518,7 +518,7 @@ Removes a notification slot of a specified type. This API uses a promise to retu ...@@ -518,7 +518,7 @@ Removes a notification slot of a specified type. This API uses a promise to retu
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise that returns no value.|
**Example** **Example**
...@@ -538,7 +538,7 @@ try { ...@@ -538,7 +538,7 @@ try {
## ActionButtonType ## ActionButtonType
Enumerates button types. Enumerates the button types.
**System capability**: SystemCapability.Notification.ReminderAgent **System capability**: SystemCapability.Notification.ReminderAgent
...@@ -551,7 +551,7 @@ Enumerates button types. ...@@ -551,7 +551,7 @@ Enumerates button types.
## ReminderType ## ReminderType
Enumerates reminder types. Enumerates the reminder types.
**System capability**: SystemCapability.Notification.ReminderAgent **System capability**: SystemCapability.Notification.ReminderAgent
...@@ -564,8 +564,7 @@ Enumerates reminder types. ...@@ -564,8 +564,7 @@ Enumerates reminder types.
## ActionButton ## ActionButton
Defines a button displayed for the reminder in the notification panel. Defines the button on the reminder displayed.
**System capability**: SystemCapability.Notification.ReminderAgent **System capability**: SystemCapability.Notification.ReminderAgent
...@@ -573,7 +572,7 @@ Defines a button displayed for the reminder in the notification panel. ...@@ -573,7 +572,7 @@ Defines a button displayed for the reminder in the notification panel.
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| title | string | Yes| Text on the button.| | title | string | Yes| Text on the button.|
| type | [ActionButtonType](#actionbuttontype) | Yes| Button type.| | type | [ActionButtonType](#actionbuttontype) | Yes| Button type.|
| wantAgent<sup>10+</sup> | [WantAgent](#wantagent) | No| Ability information that is displayed after the button is clicked.<br>**System API**: This is a system API and cannot be called by third-party applications.| | wantAgent<sup>10+</sup> | [WantAgent](#wantagent) | No| Information about the ability that is displayed after the button is clicked.<br>**System API**: This is a system API and cannot be called by third-party applications.|
## WantAgent ## WantAgent
...@@ -592,19 +591,19 @@ Defines the information about the redirected-to ability. ...@@ -592,19 +591,19 @@ Defines the information about the redirected-to ability.
## MaxScreenWantAgent ## MaxScreenWantAgent
Provides the information about the target package and ability to start automatically when the reminder is displayed in full-screen mode. This API is reserved. Provides the information about the ability that is started automatically and displayed in full-screen mode when the reminder arrives. This API is reserved.
**System capability**: SystemCapability.Notification.ReminderAgent **System capability**: SystemCapability.Notification.ReminderAgent
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| pkgName | string | Yes| Name of the package that is automatically started when the reminder arrives and the device is not in use.| | pkgName | string | Yes| Name of the target package. (If the device is in use, only a notification banner is displayed.)|
| abilityName | string | Yes| Name of the ability that is automatically started when the reminder arrives and the device is not in use.| | abilityName | string | Yes| Name of the target ability. (If the device is in use, only a notification banner is displayed.)|
## ReminderRequest ## ReminderRequest
Defines the reminder to publish. Defines the request for publishing a reminder.
**System capability**: SystemCapability.Notification.ReminderAgent **System capability**: SystemCapability.Notification.ReminderAgent
...@@ -613,7 +612,7 @@ Defines the reminder to publish. ...@@ -613,7 +612,7 @@ Defines the reminder to publish.
| reminderType | [ReminderType](#remindertype) | Yes| Type of the reminder.| | reminderType | [ReminderType](#remindertype) | Yes| Type of the reminder.|
| actionButton<sup></sup> | [ActionButton](#actionbutton) | No| Buttons displayed for the reminder in the notification panel.<br>- For common applications, a maximum of two buttons are supported.<br>- For system applications, a maximum of two buttons are supported in API version 9, and a maximum of three buttons are supported in API version 10 and later versions.| | actionButton<sup></sup> | [ActionButton](#actionbutton) | No| Buttons displayed for the reminder in the notification panel.<br>- For common applications, a maximum of two buttons are supported.<br>- For system applications, a maximum of two buttons are supported in API version 9, and a maximum of three buttons are supported in API version 10 and later versions.|
| wantAgent | [WantAgent](#wantagent) | No| Information about the ability that is redirected to when the reminder is clicked.| | wantAgent | [WantAgent](#wantagent) | No| Information about the ability that is redirected to when the reminder is clicked.|
| maxScreenWantAgent | [MaxScreenWantAgent](#maxscreenwantagent) | No| Information about the ability that is automatically started when the reminder arrives. If the device is in use, a notification will be displayed.| | maxScreenWantAgent | [MaxScreenWantAgent](#maxscreenwantagent) | No| Information about the ability that is started automatically and displayed in full-screen mode when the reminder arrives. If the device is in use, only a notification banner is displayed.<br> This API is reserved.|
| ringDuration | number | No| Ringing duration, in seconds. The default value is **1**.| | ringDuration | number | No| Ringing duration, in seconds. The default value is **1**.|
| snoozeTimes | number | No| Number of reminder snooze times. The default value is **0**.| | snoozeTimes | number | No| Number of reminder snooze times. The default value is **0**.|
| timeInterval | number | No| Reminder snooze interval, in seconds. The minimum value is 5 minutes.| | timeInterval | number | No| Reminder snooze interval, in seconds. The minimum value is 5 minutes.|
...@@ -623,8 +622,8 @@ Defines the reminder to publish. ...@@ -623,8 +622,8 @@ Defines the reminder to publish.
| snoozeContent | string | No| Content to be displayed when the reminder is snoozing.| | snoozeContent | string | No| Content to be displayed when the reminder is snoozing.|
| notificationId | number | No| Notification ID used by the reminder. If there are reminders with the same notification ID, the later one will overwrite the earlier one.| | notificationId | number | No| Notification ID used by the reminder. If there are reminders with the same notification ID, the later one will overwrite the earlier one.|
| slotType | [notification.SlotType](js-apis-notificationManager.md#slottype) | No| Type of the slot used by the reminder.| | slotType | [notification.SlotType](js-apis-notificationManager.md#slottype) | No| Type of the slot used by the reminder.|
| tapDismissed<sup>10+</sup> | boolean | No| Whether the notification is automatically cleared. The value is the same as that of [NotificationRequest.tapDismissed](js-apis-inner-notification-notificationRequest.md#notificationrequest).| | tapDismissed<sup>10+</sup> | boolean | No| Whether the reminder is automatically cleared. For details, see [NotificationRequest.tapDismissed](js-apis-inner-notification-notificationRequest.md#notificationrequest). |
| autoDeletedTime<sup>10+</sup> | number | No| Time when the notification is automatically cleared. The value is the same as that of [NotificationRequest.autoDeletedTime](js-apis-inner-notification-notificationRequest.md#notificationrequest).| | autoDeletedTime<sup>10+</sup> | number | No| Time when the reminder is automatically cleared. For details, see [NotificationRequest.autoDeletedTime](js-apis-inner-notification-notificationRequest.md#notificationrequest).|
## ReminderRequestCalendar ## ReminderRequestCalendar
......
# @ohos.resourceschedule.backgroundTaskManager (Background Task Management) # @ohos.resourceschedule.backgroundTaskManager (Background Task Management)
The **BackgroundTaskManager** module provides APIs to manage background tasks. 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.
If a service needs to be continued when the application or service module is running in the background (not visible to users), the application or service module can request a transient task to delay the suspension or a continuous task to prevent the suspension.
If an application has a task that needs to be continued when the application is switched to the background and can be completed within a short period of time, the application can request a transient task. For example, if a user chooses to clear junk files in the **Files** application and exits the application, the application can request a transient task to complete the cleanup.
If an application has a service that can be intuitively perceived by users and needs to run in the background for a long period of time (for example, music playback in the background), the application can request a continuous task.
If a privileged system application needs to use certain system resources (for example, it wants to receive common events when suspended), it can request efficiency resources.
> **NOTE** > **NOTE**
>
> 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. > 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.
...@@ -24,9 +17,11 @@ import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager' ...@@ -24,9 +17,11 @@ import backgroundTaskManager from '@ohos.resourceschedule.backgroundTaskManager'
requestSuspendDelay(reason: string, callback: Callback&lt;void&gt;): DelaySuspendInfo requestSuspendDelay(reason: string, callback: Callback&lt;void&gt;): DelaySuspendInfo
Requests delayed suspension after the application switches to the background. Requests a transient task.
The default duration of delayed suspension is 3 minutes when the battery level is higher than or equal to the broadcast low battery level and 1 minute when the battery level is lower than the broadcast low battery level. > **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.
**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask **System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
...@@ -34,14 +29,14 @@ The default duration of delayed suspension is 3 minutes when the battery level i ...@@ -34,14 +29,14 @@ The default duration of delayed suspension is 3 minutes when the battery level i
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------------------- | ---- | ------------------------------ | | -------- | -------------------- | ---- | ------------------------------ |
| reason | string | Yes | Reason for delayed transition to the suspended state. | | reason | string | Yes | Reason for requesting the transient task. |
| callback | Callback&lt;void&gt; | Yes | Invoked when a delay is about to time out. Generally, this callback is used to notify the application 6 seconds before the delay times out.| | callback | Callback&lt;void&gt; | 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.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------------- | --------- | | ------------------------------------- | --------- |
| [DelaySuspendInfo](#delaysuspendinfo) | Information about the suspension delay.| | [DelaySuspendInfo](#delaysuspendinfo) | Information about the transient task.|
**Error codes** **Error codes**
...@@ -80,7 +75,7 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er ...@@ -80,7 +75,7 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er
getRemainingDelayTime(requestId: number, callback: AsyncCallback&lt;number&gt;): void getRemainingDelayTime(requestId: number, callback: AsyncCallback&lt;number&gt;): void
Obtains the remaining duration before the application is suspended. This API uses an asynchronous callback to return the result. Obtains the remaining time of a transient task. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask **System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
...@@ -88,8 +83,8 @@ Obtains the remaining duration before the application is suspended. This API use ...@@ -88,8 +83,8 @@ Obtains the remaining duration before the application is suspended. This API use
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | --------------------------- | ---- | ---------------------------------------- | | --------- | --------------------------- | ---- | ---------------------------------------- |
| requestId | number | Yes | ID of the suspension delay request. | | requestId | number | Yes | Request ID of the transient task. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the remaining duration before the application is suspended, in milliseconds.| | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the remaining time, in milliseconds.|
**Error codes** **Error codes**
...@@ -129,9 +124,7 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er ...@@ -129,9 +124,7 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er
getRemainingDelayTime(requestId: number): Promise&lt;number&gt; getRemainingDelayTime(requestId: number): Promise&lt;number&gt;
Obtains the remaining duration before the application is suspended. This API uses a promise to return the result. Obtains the remaining time of a transient task. This API uses a promise to return the result.
**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask **System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
...@@ -139,13 +132,13 @@ Obtains the remaining duration before the application is suspended. This API use ...@@ -139,13 +132,13 @@ Obtains the remaining duration before the application is suspended. This API use
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ------ | ---- | ---------- | | --------- | ------ | ---- | ---------- |
| requestId | number | Yes | ID of the suspension delay request.| | requestId | number | Yes | Request ID of the transient task.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | ---------------------------------------- | | --------------------- | ---------------------------------------- |
| Promise&lt;number&gt; | Promise used to return the remaining duration before the application is suspended, in milliseconds.| | Promise&lt;number&gt; | Promise used to return the remaining time, in milliseconds.|
**Error codes** **Error codes**
...@@ -182,7 +175,7 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er ...@@ -182,7 +175,7 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er
cancelSuspendDelay(requestId: number): void cancelSuspendDelay(requestId: number): void
Cancels the suspension delay. Cancels a transient task.
**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask **System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
...@@ -190,7 +183,7 @@ Cancels the suspension delay. ...@@ -190,7 +183,7 @@ Cancels the suspension delay.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ------ | ---- | ---------- | | --------- | ------ | ---- | ---------- |
| requestId | number | Yes | ID of the suspension delay request.| | requestId | number | Yes | Request ID of the transient task.|
**Error codes** **Error codes**
...@@ -218,12 +211,11 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er ...@@ -218,12 +211,11 @@ For details about the error codes, see [backgroundTaskManager Error Codes](../er
} }
``` ```
## backgroundTaskManager.startBackgroundRunning ## backgroundTaskManager.startBackgroundRunning
startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent, callback: AsyncCallback&lt;void&gt;): void startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent, callback: AsyncCallback&lt;void&gt;): void
Requests a continuous task from the system. This API uses an asynchronous callback to return the result. Requests a continuous task. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.KEEP_BACKGROUND_RUNNING **Required permissions**: ohos.permission.KEEP_BACKGROUND_RUNNING
...@@ -234,9 +226,9 @@ Requests a continuous task from the system. This API uses an asynchronous callba ...@@ -234,9 +226,9 @@ Requests a continuous task from the system. This API uses an asynchronous callba
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ---------------------------------- | ---- | ---------------------------------------- | | --------- | ---------------------------------- | ---- | ---------------------------------------- |
| 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).| | 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).|
| bgMode | [BackgroundMode](#backgroundmode) | Yes | Background mode requested. | | bgMode | [BackgroundMode](#backgroundmode) | Yes | Continuous task mode. |
| wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Notification parameter, which is used to specify the target page that is redirected to when a continuous task notification is clicked. | | 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. | | 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. |
**Error codes** **Error codes**
...@@ -301,7 +293,7 @@ export default class EntryAbility extends UIAbility { ...@@ -301,7 +293,7 @@ export default class EntryAbility extends UIAbility {
startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent): Promise&lt;void&gt; startBackgroundRunning(context: Context, bgMode: BackgroundMode, wantAgent: WantAgent): Promise&lt;void&gt;
Requests a continuous task from the system. This API uses a promise to return the result. Requests a continuous task. This API uses a promise to return the result.
**Required permissions**: ohos.permission.KEEP_BACKGROUND_RUNNING **Required permissions**: ohos.permission.KEEP_BACKGROUND_RUNNING
...@@ -312,14 +304,14 @@ Requests a continuous task from the system. This API uses a promise to return th ...@@ -312,14 +304,14 @@ Requests a continuous task from the system. This API uses a promise to return th
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ---------------------------------- | ---- | ---------------------------------------- | | --------- | ---------------------------------- | ---- | ---------------------------------------- |
| 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).| | 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).|
| bgMode | [BackgroundMode](#backgroundmode) | Yes | Background mode requested. | | bgMode | [BackgroundMode](#backgroundmode) | Yes | Continuous task mode. |
| wantAgent | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes | Notification parameter, which is used to specify the target page that is redirected to when a continuous task notification is clicked. | | 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. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | ---------------- | | -------------- | ---------------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise that returns no value.|
**Error codes** **Error codes**
...@@ -380,7 +372,7 @@ export default class EntryAbility extends UIAbility { ...@@ -380,7 +372,7 @@ export default class EntryAbility extends UIAbility {
stopBackgroundRunning(context: Context, callback: AsyncCallback&lt;void&gt;): void stopBackgroundRunning(context: Context, callback: AsyncCallback&lt;void&gt;): void
Requests to cancel a continuous task. This API uses an asynchronous callback to return the result. Cancels a continuous task. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask **System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
...@@ -389,7 +381,7 @@ Requests to cancel a continuous task. This API uses an asynchronous callback to ...@@ -389,7 +381,7 @@ Requests to cancel a continuous task. This API uses an asynchronous callback to
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------- | ---- | ---------------------------------------- |
| 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).| | 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).|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. | | 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.|
**Error codes** **Error codes**
...@@ -434,9 +426,7 @@ export default class EntryAbility extends UIAbility { ...@@ -434,9 +426,7 @@ export default class EntryAbility extends UIAbility {
stopBackgroundRunning(context: Context): Promise&lt;void&gt; stopBackgroundRunning(context: Context): Promise&lt;void&gt;
Requests to cancel a continuous task. This API uses a promise to return the result. Cancels a continuous task. This API uses a promise to return the result.
**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask **System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
...@@ -450,7 +440,7 @@ Requests to cancel a continuous task. This API uses a promise to return the resu ...@@ -450,7 +440,7 @@ Requests to cancel a continuous task. This API uses a promise to return the resu
| Type | Description | | Type | Description |
| -------------- | ---------------- | | -------------- | ---------------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise that returns no value.|
**Error codes** **Error codes**
...@@ -489,10 +479,9 @@ export default class EntryAbility extends UIAbility { ...@@ -489,10 +479,9 @@ export default class EntryAbility extends UIAbility {
## backgroundTaskManager.applyEfficiencyResources ## backgroundTaskManager.applyEfficiencyResources
applyEfficiencyResources(request: [EfficiencyResourcesRequest](#efficiencyresourcesrequest)): void applyEfficiencyResources(request: EfficiencyResourcesRequest): void
Requests efficiency resources from the system. Requests efficiency resources.
A process and its application can request the same type of resources at the same time, for example, CPU resources. When the application releases the resources, the same type of resources requested by the process are also released.
**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply **System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply
...@@ -502,7 +491,7 @@ A process and its application can request the same type of resources at the same ...@@ -502,7 +491,7 @@ A process and its application can request the same type of resources at the same
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------- | ---- | ---------------------------------------- | | ------- | ------- | ---- | ---------------------------------------- |
| request | [EfficiencyResourcesRequest](#efficiencyresourcesrequest) | Yes | Necessary information carried in the request, including the resource type and timeout interval. For details, see [EfficiencyResourcesRequest](#efficiencyresourcesrequest).| | request | [EfficiencyResourcesRequest](#efficiencyresourcesrequest) | Yes | Necessary information carried in the request, including the resource type and timeout interval.|
**Error codes** **Error codes**
...@@ -542,7 +531,7 @@ try { ...@@ -542,7 +531,7 @@ try {
resetAllEfficiencyResources(): void resetAllEfficiencyResources(): void
Releases all resources that have been requested. Releases all efficiency resources.
**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply **System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.EfficiencyResourcesApply
...@@ -574,18 +563,19 @@ try { ...@@ -574,18 +563,19 @@ try {
## DelaySuspendInfo ## DelaySuspendInfo
Provides the information about the suspension delay. Defines the information about the transient task.
**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask **System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------------- | ------ | ---- | ---------------------------------------- | | --------------- | ------ | ---- | ---------------------------------------- |
| requestId | number | Yes | ID of the suspension delay request. | | requestId | number | Yes | Request ID of the transient task. |
| actualDelayTime | number | Yes | Actual suspension delay duration of the application, in milliseconds.<br>The default duration is 180000 when the battery level is higher than or equal to the broadcast low battery level and 60000 when the battery level is lower than the broadcast low battery level.| | 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.|
## BackgroundMode ## BackgroundMode
Enumerates the continuous task modes.
**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask **System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.ContinuousTask
| Name | Value | Description | | Name | Value | Description |
...@@ -596,9 +586,9 @@ Provides the information about the suspension delay. ...@@ -596,9 +586,9 @@ Provides the information about the suspension delay.
| LOCATION | 4 | Positioning and navigation. | | LOCATION | 4 | Positioning and navigation. |
| BLUETOOTH_INTERACTION | 5 | Bluetooth-related task. | | BLUETOOTH_INTERACTION | 5 | Bluetooth-related task. |
| MULTI_DEVICE_CONNECTION | 6 | Multi-device connection. | | MULTI_DEVICE_CONNECTION | 6 | Multi-device connection. |
| WIFI_INTERACTION | 7 | WLAN-related (system API).| | WIFI_INTERACTION | 7 | WLAN-related.<br>**System API**: This is a system API.|
| VOIP | 8 | Audio and video calls (system API). | | VOIP | 8 |Audio and video calls.<br>**System API**: This is a system API.|
| TASK_KEEPING | 9 | Computing task (effective only for specific devices). | | TASK_KEEPING | 9 | Computing task (for specific devices only). |
## EfficiencyResourcesRequest ## EfficiencyResourcesRequest
...@@ -611,10 +601,10 @@ Describes the parameters for requesting efficiency resources. ...@@ -611,10 +601,10 @@ Describes the parameters for requesting efficiency resources.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------------- | ------ | ---- | ---------------------------------------- | | --------------- | ------ | ---- | ---------------------------------------- |
| resourceTypes | number | Yes | Type of the resource to request. | | resourceTypes | number | Yes | Type of the resource to request. |
| isApply | boolean | Yes | Whether the request is used to apply for resources. The value **true** means that the request is used to apply for resources, and **false** means that the request is used to release resources. | | 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.|
| timeOut | number | Yes | Duration for which the resource will be used, in milliseconds. | | timeOut | number | Yes | Duration for which the resource will be used, in milliseconds. |
| isPersist | boolean | No | Whether the resource is permanently held. If the value is **true**, **timeOut** is invalid. | | 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 value **true** means that the request is initiated by a process, and **false** means that the request is initiated by an application. | | 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. |
| reason | string | Yes | Reason for requesting the resource. | | reason | string | Yes | Reason for requesting the resource. |
## ResourceType ## ResourceType
...@@ -627,12 +617,12 @@ Enumerates the efficiency resource types. ...@@ -627,12 +617,12 @@ Enumerates the efficiency resource types.
| Name | Value | Description | | Name | Value | Description |
| ----------------------- | ---- | --------------------- | | ----------------------- | ---- | --------------------- |
| CPU | 1 | CPU resources, which prevent the application from being suspended. | | CPU | 1 | CPU resource. Such type of resource prevents an application from being suspended. |
| COMMON_EVENT | 2 | Common events are not proxied when the application is 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 | System timers are not proxied when the application is suspended.| | 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 | Work Scheduler uses a loose control policy by default. For details about the constraints on the Work Scheduler usage, see [Constraints](../../task-management/work-scheduler.md#constraints).| | WORK_SCHEDULER | 8 | Deferred task resource. Such type of resource provides a loose control policy for an application.|
| BLUETOOTH | 16 | Bluetooth resources are not proxied when the application is suspended.| | 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 resources are not proxied when the application is suspended.| | 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 resources are not proxied when the application is suspended.| | AUDIO | 64 | Audio resource. Such type of resource prevents an application from being suspended when the application has an audio being played.|
| RUNNING_LOCK<sup>10+</sup> | 128 | RUNNING_LOCK resources are not proxied when the application is suspended.| | 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.| | SENSOR<sup>10+</sup> | 256 | Sensor callbacks are not intercepted.|
# @ohos.resourceschedule.workScheduler (Deferred Task Scheduling) # @ohos.resourceschedule.workScheduler (Deferred Task Scheduling)
The **workScheduler** module provides the APIs for registering, canceling, and querying deferred tasks. The **workScheduler** module provides the APIs for registering, canceling, and querying deferred tasks. You can use the APIs to register tasks that do not have high requirements on real-time performance as deferred tasks. The system schedules and executes the deferred tasks at an appropriate time, subject to the storage space, power consumption, and more.
The system schedules and executes deferred tasks at an appropriate time, subject to the storage space, power consumption, temperature, and more.
> **NOTE** > **NOTE**
> >
> - 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. > - 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.
>
> - The APIs of this module can be used only in the stage model. > - The APIs of this module can be used only in the stage model.
> - For details about the constraints on deferred task scheduling, see [Constraints](../../task-management/work-scheduler.md#constraints).
## Modules to Import ## Modules to Import
...@@ -18,9 +15,10 @@ import workScheduler from '@ohos.resourceschedule.workScheduler'; ...@@ -18,9 +15,10 @@ import workScheduler from '@ohos.resourceschedule.workScheduler';
``` ```
## workScheduler.startWork ## workScheduler.startWork
startWork(work: WorkInfo): void startWork(work: WorkInfo): void
Instructs the WorkSchedulerService to add a task to the execution queue. Starts a deferred task.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
...@@ -28,7 +26,7 @@ Instructs the WorkSchedulerService to add a task to the execution queue. ...@@ -28,7 +26,7 @@ Instructs the WorkSchedulerService to add a task to the execution queue.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | --------------------- | ---- | -------------- | | ---- | --------------------- | ---- | -------------- |
| work | [WorkInfo](#workinfo) | Yes | Task to be added to the execution queue.| | work | [WorkInfo](#workinfo) | Yes | Deferred task to start.|
**Error codes** **Error codes**
...@@ -42,7 +40,6 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes ...@@ -42,7 +40,6 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes
| 9700004 | Check workInfo failed. | | 9700004 | Check workInfo failed. |
| 9700005 | StartWork failed. | | 9700005 | StartWork failed. |
**Example** **Example**
```js ```js
...@@ -69,9 +66,10 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes ...@@ -69,9 +66,10 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes
``` ```
## workScheduler.stopWork ## workScheduler.stopWork
stopWork(work: WorkInfo, needCancel?: boolean): void stopWork(work: WorkInfo, needCancel?: boolean): void
Instructs the WorkSchedulerService to stop a task. Stops a deferred task.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
...@@ -79,8 +77,8 @@ Instructs the WorkSchedulerService to stop a task. ...@@ -79,8 +77,8 @@ Instructs the WorkSchedulerService to stop a task.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---------- | --------------------- | ---- | ---------- | | ---------- | --------------------- | ---- | ---------- |
| work | [WorkInfo](#workinfo) | Yes | Task to stop. | | work | [WorkInfo](#workinfo) | Yes | Deferred task to stop.|
| needCancel | boolean | No | Whether to cancel the task. The default value is **false**.| | needCancel | boolean | No | Whether to clear the task while stopping it.<br>The value **true** means to clear the task while stopping it, and **false** means to stop the task only. The default value is **false**.|
**Error codes** **Error codes**
...@@ -119,9 +117,10 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes ...@@ -119,9 +117,10 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes
``` ```
## workScheduler.getWorkStatus ## workScheduler.getWorkStatus
getWorkStatus(workId: number, callback : AsyncCallback\<WorkInfo>): void getWorkStatus(workId: number, callback : AsyncCallback\<WorkInfo>): void
Obtains the latest task status. This API uses an asynchronous callback to return the result. Obtains the information a deferred task. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
...@@ -129,8 +128,8 @@ Obtains the latest task status. This API uses an asynchronous callback to return ...@@ -129,8 +128,8 @@ Obtains the latest task status. This API uses an asynchronous callback to return
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------------------- | ---- | ---------------------------------------- |
| workId | number | Yes | Task ID. | | workId | number | Yes | ID of the deferred task. |
| callback | AsyncCallback\<[WorkInfo](#workinfo)> | Yes | Callback used to return the result. If the specified task ID is valid, the task status obtained from the WorkSchedulerService is returned. Otherwise, an exception is thrown.| | callback | AsyncCallback\<[WorkInfo](#workinfo)> | Yes | Callback used to return the result. If **workId** is valid, the task information obtained from WorkSchedulerService is returned. Otherwise, an exception is thrown.|
**Error codes** **Error codes**
...@@ -162,9 +161,10 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes ...@@ -162,9 +161,10 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes
``` ```
## workScheduler.getWorkStatus ## workScheduler.getWorkStatus
getWorkStatus(workId: number): Promise\<WorkInfo> getWorkStatus(workId: number): Promise\<WorkInfo>
Obtains the latest task status. This API uses a promise to return the result. Obtains the information a deferred task. This API uses a promise to return the result.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
...@@ -172,13 +172,13 @@ Obtains the latest task status. This API uses a promise to return the result. ...@@ -172,13 +172,13 @@ Obtains the latest task status. This API uses a promise to return the result.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | -------- | | ------ | ------ | ---- | -------- |
| workId | number | Yes | Task ID.| | workId | number | Yes | ID of the deferred task.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------- | ---------------------------------------- | | ------------------------------- | ---------------------------------------- |
| Promise\<[WorkInfo](#workinfo)> | Promise used to return the result. If the specified task ID is valid, the task status obtained from the WorkSchedulerService is returned. Otherwise, an exception is thrown.| | Promise\<[WorkInfo](#workinfo)> | Promise used to return the result. If **workId** is valid, the task information obtained from WorkSchedulerService is returned.|
**Error codes** **Error codes**
...@@ -208,9 +208,10 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes ...@@ -208,9 +208,10 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes
``` ```
## workScheduler.obtainAllWorks ## workScheduler.obtainAllWorks
obtainAllWorks(callback : AsyncCallback\<void>): Array\<WorkInfo> obtainAllWorks(callback : AsyncCallback\<void>): Array\<WorkInfo>
Obtains all tasks associated with the application. This API uses an asynchronous callback to return the result. Obtains all the deferred tasks. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
...@@ -218,13 +219,13 @@ Obtains all tasks associated with the application. This API uses an asynchronous ...@@ -218,13 +219,13 @@ Obtains all tasks associated with the application. This API uses an asynchronous
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------------------- | ---- | ------------------------------- | | -------- | -------------------- | ---- | ------------------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result. If all the deferred tasks are obtained, **err** is **undefined**. Otherwise, **err** is an error object.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------------------- | --------------- | | ----------------------------- | --------------- |
| Array\<[WorkInfo](#workinfo)> | All tasks associated with the application.| | Array\<[WorkInfo](#workinfo)> | All the deferred tasks.|
**Error codes** **Error codes**
...@@ -253,9 +254,10 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes ...@@ -253,9 +254,10 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes
``` ```
## workScheduler.obtainAllWorks ## workScheduler.obtainAllWorks
obtainAllWorks(): Promise\<Array\<WorkInfo>> obtainAllWorks(): Promise\<Array\<WorkInfo>>
Obtains all tasks associated with the application. This API uses a promise to return the result. Obtains all the deferred tasks. This API uses a promise to return the result.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
...@@ -263,7 +265,7 @@ Obtains all tasks associated with the application. This API uses a promise to re ...@@ -263,7 +265,7 @@ Obtains all tasks associated with the application. This API uses a promise to re
| Type | Description | | Type | Description |
| -------------------------------------- | ------------------------------ | | -------------------------------------- | ------------------------------ |
| Promise<Array\<[WorkInfo](#workinfo)>> | Promise used to return all tasks associated with the application.| | Promise<Array\<[WorkInfo](#workinfo)>> | Promise used to return all the deferred tasks.|
**Error codes** **Error codes**
...@@ -290,9 +292,10 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes ...@@ -290,9 +292,10 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes
``` ```
## workScheduler.stopAndClearWorks ## workScheduler.stopAndClearWorks
stopAndClearWorks(): void stopAndClearWorks(): void
Stops and cancels all tasks associated with the application. Stops and clears all the deferred tasks.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
...@@ -318,6 +321,7 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes ...@@ -318,6 +321,7 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes
``` ```
## workScheduler.isLastWorkTimeOut ## workScheduler.isLastWorkTimeOut
isLastWorkTimeOut(workId: number, callback : AsyncCallback\<void>): boolean isLastWorkTimeOut(workId: number, callback : AsyncCallback\<void>): boolean
Checks whether the last execution of a task timed out. This API uses an asynchronous callback to return the result. Checks whether the last execution of a task timed out. This API uses an asynchronous callback to return the result.
...@@ -328,14 +332,14 @@ Checks whether the last execution of a task timed out. This API uses an asynchro ...@@ -328,14 +332,14 @@ Checks whether the last execution of a task timed out. This API uses an asynchro
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------------------- | ---- | ---------------------------------------- | | -------- | -------------------- | ---- | ---------------------------------------- |
| workId | number | Yes | Task ID. | | workId | number | Yes | ID of the deferred task. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ---------------------------------------- | | ------- | ---------------------------------------- |
| boolean | Returns **true** if the last execution of the task timed out; returns **false** otherwise.| | boolean | The value **true** means that the last execution of the specified task times out, and **false** means the opposite.|
**Error codes** **Error codes**
...@@ -365,6 +369,7 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes ...@@ -365,6 +369,7 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes
``` ```
## workScheduler.isLastWorkTimeOut ## workScheduler.isLastWorkTimeOut
isLastWorkTimeOut(workId: number): Promise\<boolean> isLastWorkTimeOut(workId: number): Promise\<boolean>
Checks whether the last execution of a task timed out. This API uses a promise to return the result. Checks whether the last execution of a task timed out. This API uses a promise to return the result.
...@@ -375,13 +380,13 @@ Checks whether the last execution of a task timed out. This API uses a promise t ...@@ -375,13 +380,13 @@ Checks whether the last execution of a task timed out. This API uses a promise t
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | -------- | | ------ | ------ | ---- | -------- |
| workId | number | Yes | Task ID.| | workId | number | Yes | ID of the deferred task.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------- | ---------------------------------------- | | ----------------- | ---------------------------------------- |
| Promise\<boolean> | Promise used to return the result. If the last execution of the task timed out, **true** is returned. Otherwise, **false** is returned.| | Promise\<boolean> | Promise used to return the result. The value **true** means that the last execution of the specified task times out, and **false** means the opposite.|
**Error codes** **Error codes**
...@@ -411,31 +416,33 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes ...@@ -411,31 +416,33 @@ For details about the error codes, see [workScheduler Error Codes](../errorcodes
``` ```
## WorkInfo ## WorkInfo
Provides detailed information about the task. For details about the constraints on setting the **WorkInfo** parameter, see [Constraints](../../task-management/work-scheduler.md#constraints).
Defines the information about the deferred task.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------------- | --------------------------------- | ---- | ---------------- | | --------------- | --------------------------------- | ---- | ---------------- |
| workId | number | Yes | Task ID. | | workId | number | Yes | ID of the deferred task. |
| bundleName | string | Yes | Bundle name of the application that requests the task. | | bundleName | string | Yes | Bundle name of the application that requests the task. |
| abilityName | string | Yes | Name of the component to be notified by a deferred task scheduling callback.| | abilityName | string | Yes | Name of the component to be notified by a deferred task scheduling callback.|
| networkType | [NetworkType](#networktype) | No | Network type. | | networkType | [NetworkType](#networktype) | No | Network type. |
| isCharging | boolean | No | Whether the device is charging. | | isCharging | boolean | No | Whether the device needs to enter the charging state to trigger deferred task scheduling.<br>The value **true** means that the device needs to enter the charging state to trigger deferred task scheduling, and **false** means the opposite.|
| chargerType | [ChargingType](#chargingtype) | No | Charging type. | | chargerType | [ChargingType](#chargingtype) | No | Charging type. |
| batteryLevel | number | No | Battery level. | | batteryLevel | number | No | Battery level. |
| batteryStatus | [BatteryStatus](#batterystatus) | No | Battery status. | | batteryStatus | [BatteryStatus](#batterystatus) | No | Battery status. |
| storageRequest | [StorageRequest](#storagerequest) | No | Storage status. | | storageRequest | [StorageRequest](#storagerequest) | No | Storage status. |
| isRepeat | boolean | No | Whether the task is repeated. | | isRepeat | boolean | No | Whether the task is repeated.<br>The value** true** means that the task is repeated, and **false** means the opposite.|
| repeatCycleTime | number | No | Repeat interval. | | repeatCycleTime | number | No | Repeat interval. |
| repeatCount | number | No | Number of repeat times. | | repeatCount | number | No | Number of repeat times. |
| isPersisted | boolean | No | Whether to enable persistent storage for the task. | | isPersisted | boolean | No | Whether to enable persistent storage for the task.<br>The value **true** means to enable persistent storage for the task, and **false** means the opposite.|
| isDeepIdle | boolean | No | Whether the device needs to enter the idle state. | | isDeepIdle | boolean | No | Whether the device needs to enter the idle state to trigger deferred task scheduling.<br>The value **true** means that the device needs to enter the idle state to trigger deferred task scheduling, and **false** means the opposite. |
| idleWaitTime | number | No | Time to wait in the idle state. | | idleWaitTime | number | No | Time to wait in the idle state before triggering deferred task scheduling. |
| parameters | {[key: string]: number \| string \| boolean} | No | Carried parameters. | | parameters | [key: string]: number \| string \| boolean | No | Carried parameters.|
## NetworkType ## NetworkType
Enumerates the network types that can trigger task scheduling.
Enumerates the network types that can trigger deferred task scheduling.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
...@@ -449,7 +456,8 @@ Enumerates the network types that can trigger task scheduling. ...@@ -449,7 +456,8 @@ Enumerates the network types that can trigger task scheduling.
| NETWORK_TYPE_ETHERNET | 5 | Ethernet. | | NETWORK_TYPE_ETHERNET | 5 | Ethernet. |
## ChargingType ## ChargingType
Enumerates the charging types that can trigger task scheduling.
Enumerates the charging types that can trigger deferred task scheduling.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
...@@ -461,7 +469,8 @@ Enumerates the charging types that can trigger task scheduling. ...@@ -461,7 +469,8 @@ Enumerates the charging types that can trigger task scheduling.
| CHARGING_PLUGGED_WIRELESS | 3 | Wireless charging. | | CHARGING_PLUGGED_WIRELESS | 3 | Wireless charging. |
## BatteryStatus ## BatteryStatus
Enumerates the battery states that can trigger task scheduling.
Enumerates the battery statuses that can trigger deferred task scheduling.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
...@@ -472,7 +481,8 @@ Enumerates the battery states that can trigger task scheduling. ...@@ -472,7 +481,8 @@ Enumerates the battery states that can trigger task scheduling.
| BATTERY_STATUS_LOW_OR_OKAY | 2 | The battery level is restored from low to normal, or a low battery alert is displayed.| | BATTERY_STATUS_LOW_OR_OKAY | 2 | The battery level is restored from low to normal, or a low battery alert is displayed.|
## StorageRequest ## StorageRequest
Enumerates the storage states that can trigger task scheduling.
Enumerates the storage statuses that can trigger deferred task scheduling.
**System capability**: SystemCapability.ResourceSchedule.WorkScheduler **System capability**: SystemCapability.ResourceSchedule.WorkScheduler
...@@ -480,4 +490,4 @@ Enumerates the storage states that can trigger task scheduling. ...@@ -480,4 +490,4 @@ Enumerates the storage states that can trigger task scheduling.
| ------------------------- | ---- | ------------------------------ | | ------------------------- | ---- | ------------------------------ |
| STORAGE_LEVEL_LOW | 0 | The storage space is insufficient. | | STORAGE_LEVEL_LOW | 0 | The storage space is insufficient. |
| STORAGE_LEVEL_OKAY | 1 | The storage space is restored from insufficient to normal. | | STORAGE_LEVEL_OKAY | 1 | The storage space is restored from insufficient to normal. |
| STORAGE_LEVEL_LOW_OR_OKAY | 2 | The storage space is restored from insufficient to normal, or the storage space is insufficient.| | STORAGE_LEVEL_LOW_OR_OKAY | 2 | The storage space is insufficient, or the storage space is restored from insufficient to normal.|
...@@ -62,8 +62,8 @@ The table below lists the APIs used for developing deferred tasks. For details a ...@@ -62,8 +62,8 @@ The table below lists the APIs used for developing deferred tasks. For details a
| -------- | -------- | | -------- | -------- |
| startWork(work: WorkInfo): void; | Starts a deferred task.| | startWork(work: WorkInfo): void; | Starts a deferred task.|
| stopWork(work: WorkInfo, needCancel?: boolean): void; | Stops a deferred task.| | stopWork(work: WorkInfo, needCancel?: boolean): void; | Stops a deferred task.|
| getWorkStatus(workId: number, callback: AsyncCallback&lt;WorkInfo&gt;): void; | Obtains the status of a deferred task. This API uses an asynchronous callback to return the result.| | getWorkStatus(workId: number, callback: AsyncCallback&lt;WorkInfo&gt;): void; | Obtains the information about a deferred task. This API uses an asynchronous callback to return the result.|
| getWorkStatus(workId: number): Promise&lt;WorkInfo&gt;; | Obtains the status of a deferred task. This API uses a promise to return the result.| | getWorkStatus(workId: number): Promise&lt;WorkInfo&gt;; | Obtains the information about a deferred task. This API uses a promise to return the result.|
| obtainAllWorks(callback: AsyncCallback&lt;void&gt;): Array&lt;WorkInfo&gt;; | Obtains all the deferred tasks. This API uses an asynchronous callback to return the result.| | obtainAllWorks(callback: AsyncCallback&lt;void&gt;): Array&lt;WorkInfo&gt;; | Obtains all the deferred tasks. This API uses an asynchronous callback to return the result.|
| obtainAllWorks(): Promise&lt;Array&lt;WorkInfo&gt;&gt;; | Obtains all the deferred tasks. This API uses a promise to return the result.| | obtainAllWorks(): Promise&lt;Array&lt;WorkInfo&gt;&gt;; | Obtains all the deferred tasks. This API uses a promise to return the result.|
| stopAndClearWorks(): void; | Stops and clears all the deferred tasks.| | stopAndClearWorks(): void; | Stops and clears all the deferred tasks.|
...@@ -77,7 +77,7 @@ The table below lists the APIs used for developing deferred tasks. For details a ...@@ -77,7 +77,7 @@ The table below lists the APIs used for developing deferred tasks. For details a
| bundleName | string | Bundle name of the application that requests the deferred task.| | bundleName | string | Bundle name of the application that requests the deferred task.|
| abilityName | string | Name of the ability to be notified by a deferred task scheduling callback. This parameter is mandatory.| | abilityName | string | Name of the ability to be notified by a deferred task scheduling callback. This parameter is mandatory.|
| networkType | [NetworkType](../reference/apis/js-apis-resourceschedule-workScheduler.md#networktype) | Network type.| | networkType | [NetworkType](../reference/apis/js-apis-resourceschedule-workScheduler.md#networktype) | Network type.|
| isCharging | boolean | Whether the device is charging.| | isCharging | boolean | Whether the device needs to enter the charging state to trigger deferred task scheduling.|
| chargerType | [ChargingType](../reference/apis/js-apis-resourceschedule-workScheduler.md#chargingtype) | Charging type.| | chargerType | [ChargingType](../reference/apis/js-apis-resourceschedule-workScheduler.md#chargingtype) | Charging type.|
| batteryLevel | number | Battery level.| | batteryLevel | number | Battery level.|
| batteryStatus | [BatteryStatus](../reference/apis/js-apis-resourceschedule-workScheduler.md#batterystatus) | Battery status.| | batteryStatus | [BatteryStatus](../reference/apis/js-apis-resourceschedule-workScheduler.md#batterystatus) | Battery status.|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册