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