1e41f4b71Sopenharmony_ci# TransientTask
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## Overview
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ciThe TransientTask module provides C APIs for transient tasks.
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci**Since**: 13
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci## Summary
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci### Files
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci| Name| Description|
15e41f4b71Sopenharmony_ci| -------- | -------- |
16e41f4b71Sopenharmony_ci| [transient_task_api.h](transient__task__api_8h.md) | Declares the APIs for requesting, querying, and canceling transient tasks. |
17e41f4b71Sopenharmony_ci| [transient_task_type.h](transient__task__type_8h.md) | Declares the error codes and structs of a transient task. |
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci### Structs
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci| Name| Description|
23e41f4b71Sopenharmony_ci| -------- | -------- |
24e41f4b71Sopenharmony_ci| struct  [TransientTask_DelaySuspendInfo](_transient_task___delay_suspend_info.md) | Defines a struct for the returned information about a transient task. |
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci### Types
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci| Name| Description|
30e41f4b71Sopenharmony_ci| -------- | -------- |
31e41f4b71Sopenharmony_ci| typedef enum [TransientTask_ErrorCode](#transienttask_errorcode)[TransientTask_ErrorCode](#transienttask_errorcode) | Defines an enum for the error codes available for a transient task. |
32e41f4b71Sopenharmony_ci| typedef struct [TransientTask_DelaySuspendInfo](_transient_task___delay_suspend_info.md)[TransientTask_DelaySuspendInfo](#transienttask_delaysuspendinfo) | Defines a struct for the returned information about a transient task. |
33e41f4b71Sopenharmony_ci| typedef void(\* [TransientTask_Callback](#transienttask_callback)) (void) | Defines a callback for transient task timeout. |
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci### Enums
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci| Name| Description|
39e41f4b71Sopenharmony_ci| -------- | -------- |
40e41f4b71Sopenharmony_ci| [TransientTask_ErrorCode](#transienttask_errorcode) {<br>ERR_TRANSIENT_TASK_OK = 0, ERR_TRANSIENT_TASK_INVALID_PARAM = 401, ERR_TRANSIENT_TASK_PARCEL_FAILED = 9800002, ERR_TRANSIENT_TASK_TRANSACTION_FAILED = 9800003,<br>ERR_TRANSIENT_TASK_SYS_NOT_READY = 9800004, ERR_TRANSIENT_TASK_CLIENT_INFO_VERIFICATION_FAILED = 9900001, ERR_TRANSIENT_TASK_SERVICE_VERIFICATION_FAILED = 9900002<br>} | Enumerates the error codes available for a transient task. |
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci### Functions
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci| Name| Description|
46e41f4b71Sopenharmony_ci| -------- | -------- |
47e41f4b71Sopenharmony_ci| int32_t [OH_BackgroundTaskManager_RequestSuspendDelay](#oh_backgroundtaskmanager_requestsuspenddelay) (const char \*reason, [TransientTask_Callback](#transienttask_callback) callback, [TransientTask_DelaySuspendInfo](_transient_task___delay_suspend_info.md) \*info) | Requests a transient task. |
48e41f4b71Sopenharmony_ci| int32_t [OH_BackgroundTaskManager_GetRemainingDelayTime](#oh_backgroundtaskmanager_getremainingdelaytime) (int32_t requestId, int32_t \*delayTime) | Obtains the remaining time of a transient task. |
49e41f4b71Sopenharmony_ci| int32_t [OH_BackgroundTaskManager_CancelSuspendDelay](#oh_backgroundtaskmanager_cancelsuspenddelay) (int32_t requestId) | Cancels a transient task. |
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci## Type Description
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci### TransientTask_Callback
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci```
58e41f4b71Sopenharmony_citypedef void(* TransientTask_Callback) (void)
59e41f4b71Sopenharmony_ci```
60e41f4b71Sopenharmony_ci**Description**
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ciDefines a callback for transient task timeout.
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci**Since**: 13
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci### TransientTask_DelaySuspendInfo
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci```
70e41f4b71Sopenharmony_citypedef struct TransientTask_DelaySuspendInfoTransientTask_DelaySuspendInfo
71e41f4b71Sopenharmony_ci```
72e41f4b71Sopenharmony_ci**Description**
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ciDefines a struct for the returned information about a transient task.
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci**Since**: 13
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci### TransientTask_ErrorCode
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci```
82e41f4b71Sopenharmony_citypedef enum TransientTask_ErrorCodeTransientTask_ErrorCode
83e41f4b71Sopenharmony_ci```
84e41f4b71Sopenharmony_ci**Description**
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ciDefines an enum for the error codes available for a transient task.
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci**Since**: 13
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci## Enum Description
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci### TransientTask_ErrorCode
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci```
97e41f4b71Sopenharmony_cienum TransientTask_ErrorCode
98e41f4b71Sopenharmony_ci```
99e41f4b71Sopenharmony_ci**Description**
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ciEnumerates the error codes available for a transient task.
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci**Since**: 13
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci| Value| Description|
106e41f4b71Sopenharmony_ci| -------- | -------- |
107e41f4b71Sopenharmony_ci| ERR_TRANSIENT_TASK_OK  | \@error The operation is successful.&nbsp;&nbsp; |
108e41f4b71Sopenharmony_ci| ERR_TRANSIENT_TASK_INVALID_PARAM  | \@error The input parameter is incorrect. For example, the parameter is a null pointer.&nbsp;&nbsp; |
109e41f4b71Sopenharmony_ci| ERR_TRANSIENT_TASK_PARCEL_FAILED  | \@error Parcel read/write operation failed. &nbsp;&nbsp; |
110e41f4b71Sopenharmony_ci| ERR_TRANSIENT_TASK_TRANSACTION_FAILED  | \@error IPC failed.&nbsp;&nbsp; |
111e41f4b71Sopenharmony_ci| ERR_TRANSIENT_TASK_SYS_NOT_READY  | \@error The system service fails.&nbsp;&nbsp; |
112e41f4b71Sopenharmony_ci| ERR_TRANSIENT_TASK_CLIENT_INFO_VERIFICATION_FAILED  | \@error Failed to verify the client information of the transient task.&nbsp;&nbsp; |
113e41f4b71Sopenharmony_ci| ERR_TRANSIENT_TASK_SERVICE_VERIFICATION_FAILED  | \@error Failed to verify the server information of the transient task.&nbsp;&nbsp; |
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci## Function Description
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci### OH_BackgroundTaskManager_CancelSuspendDelay()
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci```
122e41f4b71Sopenharmony_ciint32_t OH_BackgroundTaskManager_CancelSuspendDelay (int32_t requestId)
123e41f4b71Sopenharmony_ci```
124e41f4b71Sopenharmony_ci**Description**
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ciCancels a transient task.
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci**Since**: 13
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci**Parameters**
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci| Name| Description|
135e41f4b71Sopenharmony_ci| -------- | -------- |
136e41f4b71Sopenharmony_ci| requestId | Request ID of the transient task. |
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci**Returns**
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ciReturns 0 if the operation is successful.
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ciReturns 401 if the input parameter is incorrect.
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ciReturns 9800002 if the Parcel read/write operation fails.
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_ciReturns 9800003 if the IPC fails.
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ciReturns 9800004 if the system service fails.
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_ciReturns 9900001 if the client information of the transient task fails to be verified.
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_ciReturns 9900002 if the server information of the transient task fails to be verified.
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_ciFor details about error codes, see [TransientTask_ErrorCode](#transienttask_errorcode).
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_ci### OH_BackgroundTaskManager_GetRemainingDelayTime()
158e41f4b71Sopenharmony_ci
159e41f4b71Sopenharmony_ci```
160e41f4b71Sopenharmony_ciint32_t OH_BackgroundTaskManager_GetRemainingDelayTime (int32_t requestId, int32_t * delayTime )
161e41f4b71Sopenharmony_ci```
162e41f4b71Sopenharmony_ci**Description**
163e41f4b71Sopenharmony_ci
164e41f4b71Sopenharmony_ciObtains the remaining time of a transient task.
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci**Since**: 13
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci**Parameters**
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci| Name| Description|
173e41f4b71Sopenharmony_ci| -------- | -------- |
174e41f4b71Sopenharmony_ci| requestId | Request ID of the transient task. |
175e41f4b71Sopenharmony_ci| time | Pointer to the remaining time. |
176e41f4b71Sopenharmony_ci
177e41f4b71Sopenharmony_ci**Returns**
178e41f4b71Sopenharmony_ci
179e41f4b71Sopenharmony_ciReturns 0 if the operation is successful.
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_ciReturns 401 if the input parameter is incorrect.
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_ciReturns 9800002 if the Parcel read/write operation fails.
184e41f4b71Sopenharmony_ci
185e41f4b71Sopenharmony_ciReturns 9800003 if the IPC fails.
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ciReturns 9800004 if the system service fails.
188e41f4b71Sopenharmony_ci
189e41f4b71Sopenharmony_ciReturns 9900001 if the client information of the transient task fails to be verified.
190e41f4b71Sopenharmony_ci
191e41f4b71Sopenharmony_ciReturns 9900002 if the server information of the transient task fails to be verified.
192e41f4b71Sopenharmony_ci
193e41f4b71Sopenharmony_ciFor details about error codes, see [TransientTask_ErrorCode](#transienttask_errorcode).
194e41f4b71Sopenharmony_ci
195e41f4b71Sopenharmony_ci
196e41f4b71Sopenharmony_ci### OH_BackgroundTaskManager_RequestSuspendDelay()
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_ci```
199e41f4b71Sopenharmony_ciint32_t OH_BackgroundTaskManager_RequestSuspendDelay (const char * reason, TransientTask_Callback callback, TransientTask_DelaySuspendInfo * info )
200e41f4b71Sopenharmony_ci```
201e41f4b71Sopenharmony_ci**Description**
202e41f4b71Sopenharmony_ci
203e41f4b71Sopenharmony_ciRequests a transient task.
204e41f4b71Sopenharmony_ci
205e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
206e41f4b71Sopenharmony_ci
207e41f4b71Sopenharmony_ci**Since**: 13
208e41f4b71Sopenharmony_ci
209e41f4b71Sopenharmony_ci**Parameters**
210e41f4b71Sopenharmony_ci
211e41f4b71Sopenharmony_ci| Name| Description|
212e41f4b71Sopenharmony_ci| -------- | -------- |
213e41f4b71Sopenharmony_ci| reason | Pointer to the reason for requesting the transient task. |
214e41f4b71Sopenharmony_ci| callback | 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. |
215e41f4b71Sopenharmony_ci| delaySuspendInfo | Pointer to the information about the transient task. |
216e41f4b71Sopenharmony_ci
217e41f4b71Sopenharmony_ci**Returns**
218e41f4b71Sopenharmony_ci
219e41f4b71Sopenharmony_ciReturns 0 if the operation is successful.
220e41f4b71Sopenharmony_ci
221e41f4b71Sopenharmony_ciReturns 401 if the input parameter is incorrect.
222e41f4b71Sopenharmony_ci
223e41f4b71Sopenharmony_ciReturns 9800002 if the Parcel read/write operation fails.
224e41f4b71Sopenharmony_ci
225e41f4b71Sopenharmony_ciReturns 9800003 if the IPC fails.
226e41f4b71Sopenharmony_ci
227e41f4b71Sopenharmony_ciReturns 9800004 if the system service fails.
228e41f4b71Sopenharmony_ci
229e41f4b71Sopenharmony_ciReturns 9900001 if the client information of the transient task fails to be verified.
230e41f4b71Sopenharmony_ci
231e41f4b71Sopenharmony_ciReturns 9900002 if the server information of the transient task fails to be verified.
232e41f4b71Sopenharmony_ci
233e41f4b71Sopenharmony_ciFor details about error codes, see [TransientTask_ErrorCode](#transienttask_errorcode).