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](_transient_task___delay_suspend_info.md)| 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** 61Defines a callback for transient task timeout. 62 63**Since**: 13 64 65 66### TransientTask_DelaySuspendInfo 67 68``` 69typedef struct TransientTask_DelaySuspendInfo TransientTask_DelaySuspendInfo 70``` 71**Description** 72Defines a struct for the returned information about a transient task. 73 74**Since**: 13 75 76 77### TransientTask_ErrorCode 78 79``` 80typedef enum TransientTask_ErrorCode TransientTask_ErrorCode 81``` 82**Description** 83Defines an enum for the error codes available for a transient task. 84 85**Since**: 13 86 87 88## Enum Description 89 90 91### TransientTask_ErrorCode 92 93``` 94enum TransientTask_ErrorCode 95``` 96**Description** 97 98Enumerates the error codes available for a transient task. 99 100**Since**: 13 101 102| Value| Description| 103| -------- | -------- | 104| ERR_TRANSIENT_TASK_OK | \@error The operation is successful. | 105| ERR_TRANSIENT_TASK_INVALID_PARAM | \@error Parameter check fails. Possible causes: 1. Mandatory parameters are not passed. 2. The parameter type is incorrect. | 106| ERR_TRANSIENT_TASK_PARCEL_FAILED | \@error Parcel read/write operation failed. | 107| ERR_TRANSIENT_TASK_TRANSACTION_FAILED | \@error IPC failed. | 108| ERR_TRANSIENT_TASK_SYS_NOT_READY | \@error The system service fails. | 109| ERR_TRANSIENT_TASK_CLIENT_INFO_VERIFICATION_FAILED | \@error Failed to verify the client information of the transient task. | 110| ERR_TRANSIENT_TASK_SERVICE_VERIFICATION_FAILED | \@error Failed to verify the server information of the transient task. | 111 112 113## Function Description 114 115 116### OH_BackgroundTaskManager_CancelSuspendDelay() 117 118``` 119int32_t OH_BackgroundTaskManager_CancelSuspendDelay (int32_t requestId) 120``` 121**Description** 122Cancels a transient task. 123 124**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask 125 126**Since**: 13 127 128**Parameters** 129 130| Name| Description| 131| -------- | -------- | 132| requestId | Request ID of the transient task. | 133 134**Returns** 135 136Returns 0 if the operation is successful. 137 138Returns 401 if the input parameter is incorrect. 139 140Returns 9800002 if the Parcel read/write operation fails. 141 142Returns 9800003 if the IPC fails. 143 144Returns 9800004 if the system service fails. 145 146Returns 9900001 if the client information of the transient task fails to be verified. 147 148Returns 9900002 if the server information of the transient task fails to be verified. 149 150For details about error codes, see [TransientTask_ErrorCode](#transienttask_errorcode). 151 152 153### OH_BackgroundTaskManager_GetRemainingDelayTime() 154 155``` 156int32_t OH_BackgroundTaskManager_GetRemainingDelayTime (int32_t requestId, int32_t * delayTime ) 157``` 158**Description** 159Obtains the remaining time of a transient task. 160 161**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask 162 163**Since**: 13 164 165**Parameters** 166 167| Name| Description| 168| -------- | -------- | 169| requestId | Request ID of the transient task. | 170| time | Pointer to the remaining time. | 171 172**Returns** 173 174Returns 0 if the operation is successful. 175 176Returns 401 if the input parameter is incorrect. 177 178Returns 9800002 if the Parcel read/write operation fails. 179 180Returns 9800003 if the IPC fails. 181 182Returns 9800004 if the system service fails. 183 184Returns 9900001 if the client information of the transient task fails to be verified. 185 186Returns 9900002 if the server information of the transient task fails to be verified. 187 188For details about error codes, see [TransientTask_ErrorCode](#transienttask_errorcode). 189 190 191### OH_BackgroundTaskManager_RequestSuspendDelay() 192 193``` 194int32_t OH_BackgroundTaskManager_RequestSuspendDelay (const char * reason, TransientTask_Callback callback, TransientTask_DelaySuspendInfo * info ) 195``` 196**Description** 197Requests a transient task. 198 199**System capability**: SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask 200 201**Since**: 13 202 203**Parameters** 204 205| Name| Description| 206| -------- | -------- | 207| reason | Pointer to the reason for requesting the transient task. | 208| 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. | 209| delaySuspendInfo | Pointer to the information about the transient task. | 210 211**Returns** 212 213Returns 0 if the operation is successful. 214 215Returns 401 if the input parameter is incorrect. 216 217Returns 9800002 if the Parcel read/write operation fails. 218 219Returns 9800003 if the IPC fails. 220 221Returns 9800004 if the system service fails. 222 223Returns 9900001 if the client information of the transient task fails to be verified. 224 225Returns 9900002 if the server information of the transient task fails to be verified. 226 227For details about error codes, see [TransientTask_ErrorCode](#transienttask_errorcode).