1# AbilityRuntime
2
3
4## Overview
5
6The AbilityRuntime module provides capabilities related to the ability framework.
7
8**System capability**: SystemCapability.Ability.AbilityRuntime.Core
9
10**Since**: 13
11
12
13## Summary
14
15
16### Files
17
18| Name| Description|
19| -------- | -------- |
20| [ability_runtime_common.h](ability__runtime__common_8h.md) | Declares the error codes of the ability framework.<br>**File to include**: <AbilityKit/ability_runtime/ability_runtime_common.h><br>**Library**: libability_runtime.so|
21| [application_context.h](application__context_8h.md) | Declares the context capability at the application level.<br>**File to include**: <AbilityKit/ability_runtime/application_context.h><br>**Library**: libability_runtime.so|
22| [context_constant.h](context__constant_8h.md) | Declares context-related enums.<br>**File to include**: <AbilityKit/ability_runtime/context_constant.h><br>**Library**: libability_runtime.so|
23
24### Enums
25
26| Name                                                        | Description                  |
27| ------------------------------------------------------------ | ---------------------- |
28| [AbilityRuntime_ErrorCode](#abilityruntime_errorcode) {<br>    ABILITY_RUNTIME_ERROR_CODE_NO_ERROR = 0,<br>    ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID = 401,<br>    ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST = 16000011,<br>} | Enumerates the error codes used by the ability framework.|
29| [AbilityRuntime_AreaMode](#abilityruntime_areamode) {<br>    ABILITY_RUNTIME_AREA_MODE_EL1 = 0,<br>    ABILITY_RUNTIME_AREA_MODE_EL2 = 1,<br>    ABILITY_RUNTIME_AREA_MODE_EL3 = 2,<br>    ABILITY_RUNTIME_AREA_MODE_EL4 = 3,<br>    ABILITY_RUNTIME_AREA_MODE_EL5 = 4<br>} | Enumerates the data encryption levels.    |
30
31### Functions
32
33| Name| Description|
34| -------- | -------- |
35| [AbilityRuntime_ErrorCode](#abilityruntime_errorcode) [OH_AbilityRuntime_ApplicationContextGetCacheDir](#oh_abilityruntime_applicationcontextgetcachedir)(char* buffer, int32_t bufferSize, int32_t* writeLength) | Obtains the application-level cache directory.|
36| [AbilityRuntime_ErrorCode](#abilityruntime_errorcode) [OH_AbilityRuntime_ApplicationContextGetAreaMode](#oh_abilityruntime_applicationcontextgetareamode)([AbilityRuntime_AreaMode](#abilityruntime_areamode)* areaMode) | Obtains the application-level data encryption level.|
37| [AbilityRuntime_ErrorCode](#abilityruntime_errorcode) [OH_AbilityRuntime_ApplicationContextGetBundleName](#oh_abilityruntime_applicationcontextgetbundlename)(char* buffer, int32_t bufferSize, int32_t* writeLength) | Obtains the bundle name of the application.|
38
39## Enum Description
40
41### AbilityRuntime_ErrorCode
42
43```
44enum AbilityRuntime_ErrorCode
45```
46
47**Description**
48
49Enumerates the error codes used by the ability framework.
50
51**Since**: 13
52
53| Value                                       | Description          |
54| --------------------------------------------- | -------------- |
55| ABILITY_RUNTIME_ERROR_CODE_NO_ERROR           | Operation successful.    |
56| ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID ARAM | Invalid parameter.    |
57| ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST  | The context does not exist.|
58
59### AbilityRuntime_AreaMode
60
61```
62enum AbilityRuntime_AreaMode
63```
64
65**Description**
66
67Enumerates the data encryption levels.
68
69**Since**: 13
70
71| Value                       | Description                                                        |
72| ----------------------------- | ------------------------------------------------------------ |
73| ABILITY_RUNTIME_AREA_MODE_EL1 | For private files, such as alarms and wallpapers, the application can place them in a directory with the device-level encryption (EL1) to ensure that they can be accessed before the user enters the password.|
74| ABILITY_RUNTIME_AREA_MODE_EL2 | For sensitive files, such as personal privacy data, the application can place them in a directory with the user-level encryption (EL2).|
75| ABILITY_RUNTIME_AREA_MODE_EL3 | For step recording, file download, or music playback that needs to read, write, and create files when the screen is locked, the application can place these files in EL3.|
76| ABILITY_RUNTIME_AREA_MODE_EL4 | For files that are related to user security information and do not need to be read, written, or created when the screen is locked, the application can place them in EL4.|
77| ABILITY_RUNTIME_AREA_MODE_EL5 | By default, sensitive user privacy files cannot be read or written on the lock screen. If such files need to be read or written on the lock screen, you can call [Access](js-apis-screenLockFileManager.md#screenlockfilemanageracquireaccess) to apply for reading or writing files before the screen is locked or create new files that can be read and written after the screen is locked. It is more appropriate to place these files in EL5.|
78
79## Function Description
80
81
82### OH_AbilityRuntime_ApplicationContextGetCacheDir
83
84```
85AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetCacheDir(char* buffer, int32_t bufferSize, int32_t* writeLength)
86```
87**Description**
88
89Obtains the application-level cache directory.
90
91**Since**: 13
92
93**Parameters**
94
95| Name| Description|
96| -------- | -------- |
97| buffer | Pointer to the buffer. The cache directory string is written to this area.|
98| bufferSize | Buffer size.|
99| writeLength | Pointer to the length of the string written to the buffer when **ABILITY_RUNTIME_ERROR_CODE_NO_ERROR** is returned.|
100
101**Returns**
102
103Returns **ABILITY_RUNTIME_ERROR_CODE_NO_ERROR** if the operation is successful.
104
105Returns **ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID** if the passed-in value of **buffer** or **writeLength** is null or the buffer size is less than the size of the string to be written.
106
107Returns **ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST** if the context of the current environment does not exist. For example, the application-level context does not exist in the [child process](c-apis-ability-childprocess.md) created by the application.
108
109### OH_AbilityRuntime_ApplicationContextGetAreaMode
110
111```
112AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetAreaMode(AbilityRuntime_AreaMode* areaMode)
113```
114
115**Description**
116
117Obtains the application-level data encryption level.
118
119**Since**: 13
120
121**Parameters**
122
123| Name    | Description                    |
124| -------- | ------------------------ |
125| areaMode | Pointer to the data encryption level.|
126
127**Returns**
128
129Returns **ABILITY_RUNTIME_ERROR_CODE_NO_ERROR** if the operation is successful.
130
131Returns **ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID** if **areaMode** is a null pointer.
132
133Returns **ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST** if the context of the current environment does not exist. For example, the application-level context does not exist in the [child process](c-apis-ability-childprocess.md) created by the application.
134
135### OH_AbilityRuntime_ApplicationContextGetBundleName
136
137```
138AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetBundleName(char* buffer, int32_t bufferSize, int32_t* writeLength)
139```
140
141**Description**
142
143Obtains the bundle name of the application.
144
145**Since**: 13
146
147**Parameters**
148
149| Name       | Description                                                        |
150| ----------- | ------------------------------------------------------------ |
151| buffer      | Pointer to the buffer. The bundle name string is written to this area.                          |
152| bufferSize  | Buffer size.                                                |
153| writeLength | Pointer to the length of the string written to the buffer when **ABILITY_RUNTIME_ERROR_CODE_NO_ERROR** is returned.|
154
155**Returns**
156
157Returns **ABILITY_RUNTIME_ERROR_CODE_NO_ERROR** if the operation is successful.
158
159Returns **ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID** if the passed-in value of **buffer** or **writeLength** is null or the buffer size is less than the size of the string to be written.
160
161Returns **ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST** if the context of the current environment does not exist. For example, the application-level context does not exist in the [child process](c-apis-ability-childprocess.md) created by the application.
162