已合并
新增context接口 #127187
wanxiaoguo创建于 1月17日
新增context接口 #127187
已合并
共 8 个文件变更+850-5
| @@ -75,11 +75,11 @@ | |||
| 75 | - [continuationResult](js-apis-continuation-continuationResult.md) | 75 | - [continuationResult](js-apis-continuation-continuationResult.md) |
| 76 | <!--Del--> | 76 | <!--Del--> |
| 77 | - [ContinuableInfo(系统接口)](js-apis-inner-application-continuableInfo-sys.md) | 77 | - [ContinuableInfo(系统接口)](js-apis-inner-application-continuableInfo-sys.md) |
| 78 | - - [ContinueCallback(系统接口)](js-apis-inner-application-continueCallback-sys.md) | 78 | + - [ContinueCallback(系统接口)](js-apis-inner-application-continueCallback-sys.md) |
| 79 | - - [ContinueMissionInfo(系统接口)](js-apis-inner-application-continueMissionInfo-sys.md) | 79 | + - [ContinueMissionInfo(系统接口)](js-apis-inner-application-continueMissionInfo-sys.md) |
| 80 | - - [MissionCallbacks(系统接口)](js-apis-inner-application-missionCallbacks-sys.md) | 80 | + - [MissionCallbacks(系统接口)](js-apis-inner-application-missionCallbacks-sys.md) |
| 81 | - - [MissionDeviceInfo(系统接口)](js-apis-inner-application-missionDeviceInfo-sys.md) | 81 | + - [MissionDeviceInfo(系统接口)](js-apis-inner-application-missionDeviceInfo-sys.md) |
| 82 | - - [MissionParameter(系统接口)](js-apis-inner-application-missionParameter-sys.md) | 82 | + - [MissionParameter(系统接口)](js-apis-inner-application-missionParameter-sys.md) |
| 83 | <!--DelEnd--> | 83 | <!--DelEnd--> |
| 84 | - FA模型能力的接口<!--fa-model--> | 84 | - FA模型能力的接口<!--fa-model--> |
| 85 | - [@ohos.ability.ability (Ability模块)](js-apis-ability-ability.md) | 85 | - [@ohos.ability.ability (Ability模块)](js-apis-ability-ability.md) |
| @@ -312,6 +312,8 @@ | |||
| 312 | - [want.h](capi-want-h.md) | 312 | - [want.h](capi-want-h.md) |
| 313 | - [ability_resource_info.h](capi-ability-resource-info-h.md) | 313 | - [ability_resource_info.h](capi-ability-resource-info-h.md) |
| 314 | - [bundle_manager_common.h](capi-bundle-manager-common-h.md) | 314 | - [bundle_manager_common.h](capi-bundle-manager-common-h.md) |
| 315 | + - [context.h](capi-context-h.md) | ||
| 316 | + - [extension_ability.h](capi-extension-ability-h.md) | ||
| 315 | - 结构体<!--ability-struct--> | 317 | - 结构体<!--ability-struct--> |
| 316 | - [AbilityBase_Element](capi-abilitybase-element.md) | 318 | - [AbilityBase_Element](capi-abilitybase-element.md) |
| 317 | - [AbilityBase_Want](capi-abilitybase-want.md) | 319 | - [AbilityBase_Want](capi-abilitybase-want.md) |
| @@ -326,6 +328,10 @@ | |||
| 326 | - [OH_NativeBundle_Metadata](capi-native-bundle-oh-nativebundle-metadata.md) | 328 | - [OH_NativeBundle_Metadata](capi-native-bundle-oh-nativebundle-metadata.md) |
| 327 | - [OH_NativeBundle_ModuleMetadata](capi-native-bundle-oh-nativebundle-modulemetadata.md) | 329 | - [OH_NativeBundle_ModuleMetadata](capi-native-bundle-oh-nativebundle-modulemetadata.md) |
| 328 | - [OH_NativeBundle_AbilityResourceInfo](capi-native-bundle-oh-nativebundle-abilityresourceinfo.md) | 330 | - [OH_NativeBundle_AbilityResourceInfo](capi-native-bundle-oh-nativebundle-abilityresourceinfo.md) |
| 331 | + - [AbilityRuntime_Context](capi-abilityruntime-abilityruntime-context.md) | ||
| 332 | + - [AbilityRuntime_Context*](capi-abilityruntime-abilityruntime-context8h.md) | ||
| 333 | + - [AbilityRuntime_ExtensionInstance](capi-abilityruntime-extensioninstance.md) | ||
| 334 | + - [AbilityRuntime_ExtensionInstance*](capi-abilityruntime-extensioninstance8h.md) | ||
| 329 | - 错误码<!--ability-arkts-errcode--> | 335 | - 错误码<!--ability-arkts-errcode--> |
| 330 | - [元能力子系统错误码](errorcode-ability.md) | 336 | - [元能力子系统错误码](errorcode-ability.md) |
| 331 | - [DistributedSchedule错误码](errorcode-DistributedSchedule.md) | 337 | - [DistributedSchedule错误码](errorcode-DistributedSchedule.md) |
Azh-cn/application-dev/reference/apis-ability-kit/capi-abilityruntime-abilityruntime-context.md+22-0
| @@ -0,0 +1,22 @@ | |||
| 1 | +# AbilityRuntime_Context | ||
| 2 | + | ||
| 3 | +<!--Kit: Ability Kit--> | ||
| 4 | +<!--Subsystem: Ability--> | ||
| 5 | +<!--Owner: @yangzhongkai--> | ||
| 6 | +<!--Designer: @yangzhongkai--> | ||
| 7 | +<!--Tester: @lixueqing513--> | ||
| 8 | +<!--Adviser: @huipeizi--> | ||
| 9 | + | ||
| 10 | +```c | ||
| 11 | +struct AbilityRuntime_Context | ||
| 12 | +``` | ||
| 13 | + | ||
| 14 | +## 概述 | ||
| 15 | + | ||
| 16 | +定义AbilityRuntime_Context结构体类型。 | ||
| 17 | + | ||
| 18 | +**起始版本:** 24 | ||
| 19 | + | ||
| 20 | +**相关模块:** [AbilityRuntime](capi-abilityruntime.md) | ||
| 21 | + | ||
| 22 | +**所在头文件:** [context.h](capi-context-h.md) | ||
Azh-cn/application-dev/reference/apis-ability-kit/capi-abilityruntime-abilityruntime-context8h.md+22-0
| @@ -0,0 +1,22 @@ | |||
| 1 | +# AbilityRuntime_Context* | ||
标题不应该是AbilityRuntime_ContextHandle吗 ![]() ![]() | |||
| 2 | + | ||
| 3 | +<!--Kit: Ability Kit--> | ||
| 4 | +<!--Subsystem: Ability--> | ||
| 5 | +<!--Owner: @yangzhongkai--> | ||
| 6 | +<!--Designer: @yangzhongkai--> | ||
| 7 | +<!--Tester: @lixueqing513--> | ||
| 8 | +<!--Adviser: @huipeizi--> | ||
| 9 | + | ||
| 10 | +```c | ||
| 11 | +typedef struct AbilityRuntime_Context* AbilityRuntime_ContextHandle | ||
| 12 | +``` | ||
| 13 | + | ||
| 14 | +## 概述 | ||
| 15 | + | ||
| 16 | +定义AbilityRuntime_Context对象指针。 | ||
| 17 | + | ||
| 18 | +**起始版本:** 24 | ||
| 19 | + | ||
| 20 | +**相关模块:** [AbilityRuntime](capi-abilityruntime.md) | ||
| 21 | + | ||
| 22 | +**所在头文件:** [context.h](capi-context-h.md) | ||
| @@ -0,0 +1,22 @@ | |||
| 1 | +# AbilityRuntime_ExtensionInstance | ||
| 2 | + | ||
| 3 | +<!--Kit: Ability Kit--> | ||
| 4 | +<!--Subsystem: Ability--> | ||
| 5 | +<!--Owner: @yangzhongkai--> | ||
| 6 | +<!--Designer: @yangzhongkai--> | ||
| 7 | +<!--Tester: @lixueqing513--> | ||
| 8 | +<!--Adviser: @huipeizi--> | ||
| 9 | + | ||
| 10 | +```c | ||
| 11 | +struct AbilityRuntime_ExtensionInstance | ||
| 12 | +``` | ||
| 13 | + | ||
| 14 | +## 概述 | ||
| 15 | + | ||
| 16 | +定义AbilityRuntime_ExtensionInstance结构体类型。 | ||
| 17 | + | ||
| 18 | +**起始版本:** 24 | ||
| 19 | + | ||
| 20 | +**相关模块:** [AbilityRuntime](capi-abilityruntime.md) | ||
| 21 | + | ||
| 22 | +**所在头文件:** [extension_ability.h](capi-extension-ability-h.md) | ||
| @@ -0,0 +1,22 @@ | |||
| 1 | +# AbilityRuntime_ExtensionInstance* | ||
同上 ![]() ![]() wanxiaoguo 3月26日 评论: 3月26日 评论: | |||
| 2 | + | ||
| 3 | +<!--Kit: Ability Kit--> | ||
| 4 | +<!--Subsystem: Ability--> | ||
| 5 | +<!--Owner: @yangzhongkai--> | ||
| 6 | +<!--Designer: @yangzhongkai--> | ||
| 7 | +<!--Tester: @lixueqing513--> | ||
| 8 | +<!--Adviser: @huipeizi--> | ||
| 9 | + | ||
| 10 | +```c | ||
| 11 | +typedef struct AbilityRuntime_ExtensionInstance* AbilityRuntime_ExtensionInstanceHandle | ||
| 12 | +``` | ||
| 13 | + | ||
| 14 | +## 概述 | ||
| 15 | + | ||
| 16 | +定义AbilityRuntime_ExtensionInstance对象指针。 | ||
| 17 | + | ||
| 18 | +**起始版本:** 24 | ||
| 19 | + | ||
| 20 | +**相关模块:** [AbilityRuntime](capi-abilityruntime.md) | ||
| 21 | + | ||
| 22 | +**所在头文件:** [extension_ability.h](capi-extension-ability-h.md) | ||
| @@ -21,5 +21,7 @@ | |||
| 21 | | -- | -- | | 21 | | -- | -- | |
| 22 | | [ability_runtime_common.h](capi-ability-runtime-common-h.md) | 提供AbilityRuntime模块的错误码。 | | 22 | | [ability_runtime_common.h](capi-ability-runtime-common-h.md) | 提供AbilityRuntime模块的错误码。 | |
| 23 | | [application_context.h](capi-application-context-h.md) | 提供应用级别上下文相关的接口。 | | 23 | | [application_context.h](capi-application-context-h.md) | 提供应用级别上下文相关的接口。 | |
| 24 | +| [context.h](capi-context-h.md) | 提供上下文数据结构[AbilityRuntime_Context](capi-abilityruntime-abilityruntime-context.md)和相关接口用于获取当前上下文的应用文件路径、数据加密等级和进程名等信息。| | ||
| 24 | | [context_constant.h](capi-context-constant-h.md) | 提供AbilityRuntime模块上下文常量的定义。 | | 25 | | [context_constant.h](capi-context-constant-h.md) | 提供AbilityRuntime模块上下文常量的定义。 | |
| 26 | +| [extension_ability.h](capi-extension-ability-h.md) | 提供ExtensionAbility回调函数类型声明和入口函数名称声明。 | | ||
| 25 | | [start_options.h](capi-start-options-h.md) | 提供应用启动参数数据结构[AbilityRuntime_StartOptions](capi-abilityruntime-startoptions.md)以及设置和获取相关函数。 | | 27 | | [start_options.h](capi-start-options-h.md) | 提供应用启动参数数据结构[AbilityRuntime_StartOptions](capi-abilityruntime-startoptions.md)以及设置和获取相关函数。 | |
| @@ -0,0 +1,656 @@ | |||
| 1 | +# context.h | ||
| 2 | + | ||
| 3 | +<!--Kit: Ability Kit--> | ||
| 4 | +<!--Subsystem: Ability--> | ||
| 5 | +<!--Owner: @yangzhongkai--> | ||
| 6 | +<!--Designer: @yangzhongkai--> | ||
| 7 | +<!--Tester: @lixueqing513--> | ||
| 8 | +<!--Adviser: @huipeizi--> | ||
| 9 | + | ||
| 10 | +## 概述 | ||
| 11 | + | ||
| 12 | +提供上下文数据结构[AbilityRuntime_Context](capi-abilityruntime-abilityruntime-context.md)和相关接口用于获取当前上下文的应用文件路径、数据加密等级和进程名等信息。 | ||
| 13 | + | ||
| 14 | +**引用文件:** <AbilityKit/ability_runtime/context.h> | ||
| 15 | + | ||
| 16 | +**库:** libability_runtime.so | ||
| 17 | + | ||
| 18 | +**系统能力:** SystemCapability.Ability.AbilityRuntime.Core | ||
| 19 | + | ||
| 20 | +**起始版本:** 24 | ||
| 21 | + | ||
| 22 | +**相关模块:** [AbilityRuntime](capi-abilityruntime.md) | ||
| 23 | + | ||
| 24 | +## 汇总 | ||
| 25 | + | ||
| 26 | +### 结构体 | ||
| 27 | + | ||
| 28 | +| 名称 | typedef关键字 | 描述 | | ||
| 29 | +| -- | -- | -- | | ||
| 30 | +| [AbilityRuntime_Context](capi-abilityruntime-abilityruntime-context.md) | - | 定义AbilityRuntime_Context结构体类型。 | | ||
| 31 | +| [AbilityRuntime_Context*](capi-abilityruntime-abilityruntime-context8h.md) | AbilityRuntime_ContextHandle | 定义指向AbilityRuntime_Context的指针。 | | ||
| 32 | + | ||
| 33 | +### 函数 | ||
| 34 | + | ||
| 35 | +| 名称 | 描述 | | ||
| 36 | +| -- | -- | | ||
| 37 | +| [AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetCacheDir(AbilityRuntime_ContextHandle context, char* buffer, int32_t bufferSize, int32_t* writeLength)](#oh_abilityruntime_context_getcachedir) | 获取上下文的缓存目录。 | | ||
L 获取上下文的xxx 这里的描述可以优化下 ![]() ![]() | |||
| 38 | +| [AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetTempDir(AbilityRuntime_ContextHandle context, char* buffer, const int32_t bufferSize, int32_t* writeLength)](#oh_abilityruntime_context_gettempdir) | 获取上下文的临时文件目录。 | | ||
| 39 | +| [AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetFilesDir(AbilityRuntime_ContextHandle context, char* buffer, const int32_t bufferSize, int32_t* writeLength)](#oh_abilityruntime_context_getfilesdir) | 获取上下文的通用文件目录。 | | ||
| 40 | +| [AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetDatabaseDir(AbilityRuntime_ContextHandle context, char* buffer, const int32_t bufferSize, int32_t* writeLength)](#oh_abilityruntime_context_getdatabasedir) | 获取上下文的数据库文件目录。 | | ||
| 41 | +| [AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetPreferencesDir(AbilityRuntime_ContextHandle context, char* buffer, const int32_t bufferSize, int32_t* writeLength)](#oh_abilityruntime_context_getpreferencesdir) | 获取上下文的首选项文件目录。 | | ||
| 42 | +| [AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetBundleCodeDir(AbilityRuntime_ContextHandle context, char* buffer, const int32_t bufferSize, int32_t* writeLength)](#oh_abilityruntime_context_getbundlecodedir) | 获取上下文的安装文件目录。 | | ||
| 43 | +| [AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetDistributedFilesDir(AbilityRuntime_ContextHandle context, char* buffer, const int32_t bufferSize, int32_t* writeLength)](#oh_abilityruntime_context_getdistributedfilesdir) | 获取上下文的分布式文件目录。 | | ||
| 44 | +| [AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetResourceDir(AbilityRuntime_ContextHandle context, char* buffer, const int32_t bufferSize, int32_t* writeLength)](#oh_abilityruntime_context_getresourcedir) | 获取上下文的资源目录。 | | ||
| 45 | +| [AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetCloudFileDir(AbilityRuntime_ContextHandle context, char* buffer, const int32_t bufferSize, int32_t* writeLength)](#oh_abilityruntime_context_getcloudfiledir) | 获取上下文的云文件目录。 | | ||
| 46 | +| [AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetAreaMode(AbilityRuntime_ContextHandle context, AbilityRuntime_AreaMode* areaMode)](#oh_abilityruntime_context_getareamode) | 获取上下文的数据加密等级。 | | ||
| 47 | +| [AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_SetAreaMode(AbilityRuntime_ContextHandle context, AbilityRuntime_AreaMode areaMode)](#oh_abilityruntime_context_setareamode) | 设置上下文的数据加密等级。 | | ||
| 48 | +| [AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetLogFileDir(AbilityRuntime_ContextHandle context, char* buffer, const int32_t bufferSize, int32_t* writeLength)](#oh_abilityruntime_context_getlogfiledir) | 获取上下文的日志文件目录。 | | ||
| 49 | +| [AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetProcessName(AbilityRuntime_ContextHandle context, char* buffer, int32_t bufferSize, int32_t* writeLength)](#oh_abilityruntime_context_getprocessname) | 获取上下文所在的进程名称。 | | ||
| 50 | + | ||
| 51 | +## 函数说明 | ||
| 52 | + | ||
| 53 | +### OH_AbilityRuntime_Context_GetCacheDir() | ||
| 54 | + | ||
| 55 | +```c | ||
| 56 | +AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetCacheDir( | ||
| 57 | + AbilityRuntime_ContextHandle context, char* buffer, int32_t bufferSize, int32_t* writeLength) | ||
| 58 | +``` | ||
| 59 | + | ||
| 60 | +**描述** | ||
| 61 | + | ||
| 62 | +获取上下文的缓存目录。 | ||
| 63 | + | ||
| 64 | +**起始版本:** 24 | ||
| 65 | + | ||
| 66 | +**参数:** | ||
| 67 | + | ||
| 68 | +| 参数项 | 描述 | | ||
| 69 | +| -- | -- | | ||
| 70 | +| [AbilityRuntime_ContextHandle](capi-abilityruntime-abilityruntime-context8h.md) context | 要获取缓存目录的上下文。 | | ||
| 71 | +| char* buffer | 指向缓冲区的指针,用于接收上下文的缓存目录。 | | ||
| 72 | +| int32_t bufferSize | 缓冲区大小,单位为字节。 | | ||
| 73 | +| int32_t* writeLength | 在返回[ABILITY_RUNTIME_ERROR_CODE_NO_ERROR](capi-ability-runtime-common-h.md#abilityruntime_errorcode)时,表示实际写入到缓冲区的字符串长度,单位为字节。 | | ||
| 74 | + | ||
| 75 | +**返回:** | ||
| 76 | + | ||
| 77 | +| 类型 | 说明 | | ||
| 78 | +| -- | -- | | ||
| 79 | +| [AbilityRuntime_ErrorCode](capi-ability-runtime-common-h.md#abilityruntime_errorcode) | 返回执行结果。<br>ABILITY_RUNTIME_ERROR_CODE_NO_ERROR - 操作成功。<br>ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID - 入参buffer或writeLength为空或context为空,或缓冲区大小小于需要写入的大小。<br>ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST - 上下文不存在。 | | ||
| 80 | + | ||
| 81 | +**示例代码:** | ||
| 82 | + | ||
| 83 | +```c | ||
| 84 | +#include <AbilityKit/ability_runtime/context.h> | ||
| 85 | + | ||
| 86 | +// 接收一个context 对象 | ||
| 87 | +void testGetCacheDir(AbilityRuntime_ContextHandle context) | ||
| 88 | +{ | ||
| 89 | + char buffer[1024] = {0}; | ||
| 90 | + int32_t cacheDirSize = 0; | ||
| 91 | + AbilityRuntime_ErrorCode errorCode = ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; | ||
| 92 | + errorCode = OH_AbilityRuntime_Context_GetCacheDir(context, buffer, 1024, &cacheDirSize); | ||
| 93 | + if (errorCode != ABILITY_RUNTIME_ERROR_CODE_NO_ERROR) { | ||
| 94 | + // 记录错误日志以及其他业务处理 | ||
| 95 | + } | ||
| 96 | + // 正常业务处理 | ||
| 97 | +} | ||
| 98 | +``` | ||
| 99 | + | ||
| 100 | +### OH_AbilityRuntime_Context_GetTempDir() | ||
| 101 | + | ||
| 102 | +```c | ||
| 103 | +AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetTempDir( | ||
| 104 | + AbilityRuntime_ContextHandle context, char* buffer, const int32_t bufferSize, int32_t* writeLength) | ||
| 105 | +``` | ||
| 106 | + | ||
| 107 | +**描述** | ||
| 108 | + | ||
| 109 | +获取上下文的临时文件目录。 | ||
| 110 | + | ||
| 111 | +**起始版本:** 24 | ||
| 112 | + | ||
| 113 | +**参数:** | ||
| 114 | + | ||
| 115 | +| 参数项 | 描述 | | ||
| 116 | +| -- | -- | | ||
| 117 | +| [AbilityRuntime_ContextHandle](capi-abilityruntime-abilityruntime-context8h.md) context | 要获取临时文件目录的上下文。 | | ||
| 118 | +| char* buffer | 指向缓冲区的指针,用于接收上下文的临时文件目录。 | | ||
| 119 | +| const int32_t bufferSize | 缓冲区大小,单位为字节。 | | ||
| 120 | +| int32_t* writeLength | 在返回[ABILITY_RUNTIME_ERROR_CODE_NO_ERROR](capi-ability-runtime-common-h.md#abilityruntime_errorcode)时,表示实际写入到缓冲区的字符串长度,单位为字节。 | | ||
| 121 | + | ||
| 122 | +**返回:** | ||
| 123 | + | ||
| 124 | +| 类型 | 说明 | | ||
| 125 | +| -- | -- | | ||
| 126 | +| [AbilityRuntime_ErrorCode](capi-ability-runtime-common-h.md#abilityruntime_errorcode) | 返回执行结果。<br>ABILITY_RUNTIME_ERROR_CODE_NO_ERROR - 操作成功。<br>ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID - 入参buffer或writeLength为空或context为空,或缓冲区大小小于需要写入的大小。<br>ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST - 上下文不存在。 | | ||
| 127 | + | ||
| 128 | +**示例代码:** | ||
| 129 | + | ||
| 130 | +```c | ||
| 131 | +#include <AbilityKit/ability_runtime/context.h> | ||
| 132 | + | ||
| 133 | +// 接收一个context 对象 | ||
| 134 | +void testGetTempDir(AbilityRuntime_ContextHandle context) | ||
| 135 | +{ | ||
| 136 | + char buffer[1024] = {0}; | ||
| 137 | + int32_t tempDirSize = 0; | ||
| 138 | + AbilityRuntime_ErrorCode errorCode = ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; | ||
| 139 | + errorCode = OH_AbilityRuntime_Context_GetTempDir(context, buffer, 1024, &tempDirSize); | ||
| 140 | + if (errorCode != ABILITY_RUNTIME_ERROR_CODE_NO_ERROR) { | ||
| 141 | + // 记录错误日志以及其他业务处理 | ||
| 142 | + } | ||
| 143 | + // 正常业务处理 | ||
| 144 | +} | ||
| 145 | +``` | ||
| 146 | + | ||
| 147 | +### OH_AbilityRuntime_Context_GetFilesDir() | ||
| 148 | + | ||
| 149 | +```c | ||
| 150 | +AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetFilesDir( | ||
| 151 | + AbilityRuntime_ContextHandle context, char* buffer, const int32_t bufferSize, int32_t* writeLength) | ||
| 152 | +``` | ||
| 153 | + | ||
| 154 | +**描述** | ||
| 155 | + | ||
| 156 | +获取上下文的通用文件目录。 | ||
| 157 | + | ||
| 158 | +**起始版本:** 24 | ||
| 159 | + | ||
| 160 | +**参数:** | ||
| 161 | + | ||
| 162 | +| 参数项 | 描述 | | ||
| 163 | +| -- | -- | | ||
| 164 | +| [AbilityRuntime_ContextHandle](capi-abilityruntime-abilityruntime-context8h.md) context | 要获取通用文件目录的上下文。| | ||
| 165 | +| char* buffer | 指向缓冲区的指针,用于接收上下文的通用文件目录。 | | ||
| 166 | +| const int32_t bufferSize | 缓冲区大小,单位为字节。 | | ||
| 167 | +| int32_t* writeLength | 在返回[ABILITY_RUNTIME_ERROR_CODE_NO_ERROR](capi-ability-runtime-common-h.md#abilityruntime_errorcode)时,表示实际写入到缓冲区的字符串长度,单位为字节。 | | ||
| 168 | + | ||
| 169 | +**返回:** | ||
| 170 | + | ||
| 171 | +| 类型 | 说明 | | ||
| 172 | +| -- | -- | | ||
| 173 | +| [AbilityRuntime_ErrorCode](capi-ability-runtime-common-h.md#abilityruntime_errorcode) | 返回执行结果。<br>ABILITY_RUNTIME_ERROR_CODE_NO_ERROR - 操作成功。<br>ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID - 入参buffer或writeLength为空或context为空,或缓冲区大小小于需要写入的大小。<br>ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST - 上下文不存在。 | | ||
| 174 | + | ||
| 175 | +**示例代码:** | ||
| 176 | + | ||
| 177 | +```c | ||
| 178 | +#include <AbilityKit/ability_runtime/context.h> | ||
| 179 | + | ||
| 180 | +// 接收一个context 对象 | ||
| 181 | +void testGetFilesDir(AbilityRuntime_ContextHandle context) | ||
| 182 | +{ | ||
| 183 | + char buffer[1024] = {0}; | ||
| 184 | + int32_t filesDirSize = 0; | ||
| 185 | + AbilityRuntime_ErrorCode errorCode = ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; | ||
| 186 | + errorCode = OH_AbilityRuntime_Context_GetFilesDir(context, buffer, 1024, &filesDirSize); | ||
| 187 | + if (errorCode != ABILITY_RUNTIME_ERROR_CODE_NO_ERROR) { | ||
| 188 | + // 记录错误日志以及其他业务处理 | ||
| 189 | + } | ||
| 190 | + // 正常业务处理 | ||
| 191 | +} | ||
| 192 | +``` | ||
| 193 | + | ||
| 194 | +### OH_AbilityRuntime_Context_GetDatabaseDir() | ||
| 195 | + | ||
| 196 | +```c | ||
| 197 | +AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetDatabaseDir( | ||
| 198 | + AbilityRuntime_ContextHandle context, char* buffer, const int32_t bufferSize, int32_t* writeLength) | ||
| 199 | +``` | ||
| 200 | + | ||
| 201 | +**描述** | ||
| 202 | + | ||
| 203 | +获取上下文的数据库文件目录。 | ||
| 204 | + | ||
| 205 | +**起始版本:** 24 | ||
| 206 | + | ||
| 207 | +**参数:** | ||
| 208 | + | ||
| 209 | +| 参数项 | 描述 | | ||
| 210 | +| -- | -- | | ||
| 211 | +| [AbilityRuntime_ContextHandle](capi-abilityruntime-abilityruntime-context8h.md) context | 要获取数据库文件目录的上下文。 | | ||
| 212 | +| char* buffer | 指向缓冲区的指针,用于接收上下文的数据库文件目录。 | | ||
| 213 | +| const int32_t bufferSize | 缓冲区大小,单位为字节。 | | ||
| 214 | +| int32_t* writeLength | 在返回[ABILITY_RUNTIME_ERROR_CODE_NO_ERROR](capi-ability-runtime-common-h.md#abilityruntime_errorcode)时,表示实际写入到缓冲区的字符串长度,单位为字节。 | | ||
| 215 | + | ||
| 216 | +**返回:** | ||
| 217 | + | ||
| 218 | +| 类型 | 说明 | | ||
| 219 | +| -- | -- | | ||
| 220 | +| [AbilityRuntime_ErrorCode](capi-ability-runtime-common-h.md#abilityruntime_errorcode) | 返回执行结果。<br>ABILITY_RUNTIME_ERROR_CODE_NO_ERROR - 操作成功。<br>ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID - 入参buffer或writeLength为空或context为空,或缓冲区大小小于需要写入的大小。<br>ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST - 上下文不存在。 | | ||
| 221 | + | ||
| 222 | +**示例代码:** | ||
| 223 | + | ||
| 224 | +```c | ||
| 225 | +#include <AbilityKit/ability_runtime/context.h> | ||
| 226 | + | ||
| 227 | +// 接收一个context 对象 | ||
| 228 | +void testGetDatabaseDir(AbilityRuntime_ContextHandle context) | ||
| 229 | +{ | ||
| 230 | + char buffer[1024] = {0}; | ||
| 231 | + int32_t databaseDirSize = 0; | ||
| 232 | + AbilityRuntime_ErrorCode errorCode = ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; | ||
| 233 | + errorCode = OH_AbilityRuntime_Context_GetDatabaseDir(context, buffer, 1024, &databaseDirSize); | ||
| 234 | + if (errorCode != ABILITY_RUNTIME_ERROR_CODE_NO_ERROR) { | ||
| 235 | + // 记录错误日志以及其他业务处理 | ||
| 236 | + } | ||
| 237 | + // 正常业务处理 | ||
| 238 | +} | ||
| 239 | +``` | ||
| 240 | + | ||
| 241 | +### OH_AbilityRuntime_Context_GetPreferencesDir() | ||
| 242 | + | ||
| 243 | +```c | ||
| 244 | +AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetPreferencesDir( | ||
| 245 | + AbilityRuntime_ContextHandle context, char* buffer, const int32_t bufferSize, int32_t* writeLength) | ||
| 246 | +``` | ||
| 247 | + | ||
| 248 | +**描述** | ||
| 249 | + | ||
| 250 | +获取上下文的首选项文件目录。 | ||
| 251 | + | ||
| 252 | +**起始版本:** 24 | ||
| 253 | + | ||
| 254 | +**参数:** | ||
| 255 | + | ||
| 256 | +| 参数项 | 描述 | | ||
| 257 | +| -- | -- | | ||
| 258 | +| [AbilityRuntime_ContextHandle](capi-abilityruntime-abilityruntime-context8h.md) context | 要获取首选项文件目录的上下文。 | | ||
| 259 | +| char* buffer | 指向缓冲区的指针,用于接收上下文的首选项文件目录。 | | ||
| 260 | +| const int32_t bufferSize | 缓冲区大小,单位为字节。 | | ||
| 261 | +| int32_t* writeLength | 在返回[ABILITY_RUNTIME_ERROR_CODE_NO_ERROR](capi-ability-runtime-common-h.md#abilityruntime_errorcode)时,表示实际写入到缓冲区的字符串长度,单位为字节。 | | ||
| 262 | + | ||
| 263 | +**返回:** | ||
| 264 | + | ||
| 265 | +| 类型 | 说明 | | ||
| 266 | +| -- | -- | | ||
| 267 | +| [AbilityRuntime_ErrorCode](capi-ability-runtime-common-h.md#abilityruntime_errorcode) | 返回执行结果。<br>ABILITY_RUNTIME_ERROR_CODE_NO_ERROR - 操作成功。<br>ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID - 入参buffer或writeLength为空或context为空,或缓冲区大小小于需要写入的大小。<br>ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST - 上下文不存在。 | | ||
| 268 | + | ||
| 269 | +**示例代码:** | ||
| 270 | + | ||
| 271 | +```c | ||
| 272 | +#include <AbilityKit/ability_runtime/context.h> | ||
| 273 | + | ||
| 274 | +// 接收一个context 对象 | ||
| 275 | +void testGetPreferencesDir(AbilityRuntime_ContextHandle context) | ||
| 276 | +{ | ||
| 277 | + char buffer[1024] = {0}; | ||
| 278 | + int32_t preferencesDirSize = 0; | ||
| 279 | + AbilityRuntime_ErrorCode errorCode = ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; | ||
| 280 | + errorCode = OH_AbilityRuntime_Context_GetPreferencesDir(context, buffer, 1024, &preferencesDirSize); | ||
| 281 | + if (errorCode != ABILITY_RUNTIME_ERROR_CODE_NO_ERROR) { | ||
| 282 | + // 记录错误日志以及其他业务处理 | ||
| 283 | + } | ||
| 284 | + // 正常业务处理 | ||
| 285 | +} | ||
| 286 | +``` | ||
| 287 | + | ||
| 288 | +### OH_AbilityRuntime_Context_GetBundleCodeDir() | ||
| 289 | + | ||
| 290 | +```c | ||
| 291 | +AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetBundleCodeDir( | ||
| 292 | + AbilityRuntime_ContextHandle context, char* buffer, const int32_t bufferSize, int32_t* writeLength) | ||
| 293 | +``` | ||
| 294 | + | ||
| 295 | +**描述** | ||
| 296 | + | ||
| 297 | +获取上下文的安装文件目录。 | ||
| 298 | + | ||
| 299 | +**起始版本:** 24 | ||
| 300 | + | ||
| 301 | +**参数:** | ||
| 302 | + | ||
| 303 | +| 参数项 | 描述 | | ||
| 304 | +| -- | -- | | ||
| 305 | +| [AbilityRuntime_ContextHandle](capi-abilityruntime-abilityruntime-context8h.md) context | 要获取安装文件目录的上下文。 | | ||
| 306 | +| char* buffer | 指向缓冲区的指针,用于接收上下文的安装文件目录。 | | ||
| 307 | +| const int32_t bufferSize | 缓冲区大小,单位为字节。 | | ||
| 308 | +| int32_t* writeLength | 在返回[ABILITY_RUNTIME_ERROR_CODE_NO_ERROR](capi-ability-runtime-common-h.md#abilityruntime_errorcode)时,表示实际写入到缓冲区的字符串长度,单位为字节。 | | ||
| 309 | + | ||
| 310 | +**返回:** | ||
| 311 | + | ||
| 312 | +| 类型 | 说明 | | ||
| 313 | +| -- | -- | | ||
| 314 | +| [AbilityRuntime_ErrorCode](capi-ability-runtime-common-h.md#abilityruntime_errorcode) | 返回执行结果。<br>ABILITY_RUNTIME_ERROR_CODE_NO_ERROR - 操作成功。<br>ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID - 入参buffer或writeLength为空或context为空,或缓冲区大小小于需要写入的大小。<br>ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST - 上下文不存在。 | | ||
| 315 | + | ||
| 316 | +**示例代码:** | ||
| 317 | + | ||
| 318 | +```c | ||
| 319 | +#include <AbilityKit/ability_runtime/context.h> | ||
| 320 | + | ||
| 321 | +// 接收一个context 对象 | ||
| 322 | +void testGetBundleCodeDir(AbilityRuntime_ContextHandle context) | ||
| 323 | +{ | ||
| 324 | + char buffer[1024] = {0}; | ||
| 325 | + int32_t bundleCodeDirSize = 0; | ||
| 326 | + AbilityRuntime_ErrorCode errorCode = ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; | ||
| 327 | + errorCode = OH_AbilityRuntime_Context_GetBundleCodeDir(context, buffer, 1024, &bundleCodeDirSize); | ||
| 328 | + if (errorCode != ABILITY_RUNTIME_ERROR_CODE_NO_ERROR) { | ||
| 329 | + // 记录错误日志以及其他业务处理 | ||
| 330 | + } | ||
| 331 | + // 正常业务处理 | ||
| 332 | +} | ||
| 333 | +``` | ||
| 334 | + | ||
| 335 | +### OH_AbilityRuntime_Context_GetDistributedFilesDir() | ||
| 336 | + | ||
| 337 | +```c | ||
| 338 | +AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetDistributedFilesDir( | ||
| 339 | + AbilityRuntime_ContextHandle context, char* buffer, const int32_t bufferSize, int32_t* writeLength) | ||
| 340 | +``` | ||
| 341 | + | ||
| 342 | +**描述** | ||
| 343 | + | ||
| 344 | +获取上下文的分布式文件目录。 | ||
| 345 | + | ||
| 346 | +**起始版本:** 24 | ||
| 347 | + | ||
| 348 | +**参数:** | ||
| 349 | + | ||
| 350 | +| 参数项 | 描述 | | ||
| 351 | +| -- | -- | | ||
| 352 | +| [AbilityRuntime_ContextHandle](capi-abilityruntime-abilityruntime-context8h.md) context | 要获取分布式文件目录的上下文。 | | ||
| 353 | +| char* buffer | 指向缓冲区的指针,用于接收上下文的分布式文件目录。 | | ||
| 354 | +| const int32_t bufferSize | 缓冲区大小,单位为字节。 | | ||
| 355 | +| int32_t* writeLength | 在返回[ABILITY_RUNTIME_ERROR_CODE_NO_ERROR](capi-ability-runtime-common-h.md#abilityruntime_errorcode)时,表示实际写入到缓冲区的字符串长度,单位为字节。 | | ||
| 356 | + | ||
| 357 | +**返回:** | ||
| 358 | + | ||
| 359 | +| 类型 | 说明 | | ||
| 360 | +| -- | -- | | ||
| 361 | +| [AbilityRuntime_ErrorCode](capi-ability-runtime-common-h.md#abilityruntime_errorcode) | 返回执行结果。<br>ABILITY_RUNTIME_ERROR_CODE_NO_ERROR - 操作成功。<br>ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID - 入参buffer或writeLength为空或context为空,或缓冲区大小小于需要写入的大小。<br>ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST - 上下文不存在。 | | ||
| 362 | + | ||
| 363 | +**示例代码:** | ||
| 364 | + | ||
| 365 | +```c | ||
| 366 | +#include <AbilityKit/ability_runtime/context.h> | ||
| 367 | + | ||
| 368 | +// 接收一个context 对象 | ||
| 369 | +void testGetDistributedFilesDir(AbilityRuntime_ContextHandle context) | ||
| 370 | +{ | ||
| 371 | + char buffer[1024] = {0}; | ||
| 372 | + int32_t distributedFilesDirSize = 0; | ||
| 373 | + AbilityRuntime_ErrorCode errorCode = ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; | ||
| 374 | + errorCode = OH_AbilityRuntime_Context_GetDistributedFilesDir(context, buffer, 1024, &distributedFilesDirSize); | ||
| 375 | + if (errorCode != ABILITY_RUNTIME_ERROR_CODE_NO_ERROR) { | ||
| 376 | + // 记录错误日志以及其他业务处理 | ||
| 377 | + } | ||
| 378 | + // 正常业务处理 | ||
| 379 | +} | ||
| 380 | +``` | ||
| 381 | + | ||
| 382 | +### OH_AbilityRuntime_Context_GetResourceDir() | ||
| 383 | + | ||
| 384 | +```c | ||
| 385 | +AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetResourceDir( | ||
| 386 | + AbilityRuntime_ContextHandle context, char* buffer, const int32_t bufferSize, int32_t* writeLength) | ||
| 387 | +``` | ||
| 388 | + | ||
| 389 | +**描述** | ||
| 390 | + | ||
| 391 | +获取上下文的资源目录。 | ||
| 392 | + | ||
| 393 | +**起始版本:** 24 | ||
| 394 | + | ||
| 395 | +**参数:** | ||
| 396 | + | ||
| 397 | +| 参数项 | 描述 | | ||
| 398 | +| -- | -- | | ||
| 399 | +| [AbilityRuntime_ContextHandle](capi-abilityruntime-abilityruntime-context8h.md) context | 要获取资源目录的上下文。 | | ||
| 400 | +| char* buffer | 指向缓冲区的指针,用于接收上下文的资源目录。 | | ||
| 401 | +| const int32_t bufferSize | 缓冲区大小,单位为字节。 | | ||
| 402 | +| int32_t* writeLength | 在返回[ABILITY_RUNTIME_ERROR_CODE_NO_ERROR](capi-ability-runtime-common-h.md#abilityruntime_errorcode)时,表示实际写入到缓冲区的字符串长度,单位为字节。 | | ||
| 403 | + | ||
| 404 | +**返回:** | ||
| 405 | + | ||
| 406 | +| 类型 | 说明 | | ||
| 407 | +| -- | -- | | ||
| 408 | +| [AbilityRuntime_ErrorCode](capi-ability-runtime-common-h.md#abilityruntime_errorcode) | 返回执行结果。<br>ABILITY_RUNTIME_ERROR_CODE_NO_ERROR - 操作成功。<br>ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID - 入参buffer或writeLength为空或context为空,或缓冲区大小小于需要写入的大小。<br>ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST - 上下文不存在。 | | ||
| 409 | + | ||
| 410 | +**示例代码:** | ||
| 411 | + | ||
| 412 | +```c | ||
| 413 | +#include <AbilityKit/ability_runtime/context.h> | ||
| 414 | + | ||
| 415 | +// 接收一个context 对象 | ||
| 416 | +void testGetResourceDir(AbilityRuntime_ContextHandle context) | ||
| 417 | +{ | ||
| 418 | + char buffer[1024] = {0}; | ||
| 419 | + int32_t resourceDirSize = 0; | ||
| 420 | + AbilityRuntime_ErrorCode errorCode = ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; | ||
| 421 | + errorCode = OH_AbilityRuntime_Context_GetResourceDir(context, buffer, 1024, &resourceDirSize); | ||
| 422 | + if (errorCode != ABILITY_RUNTIME_ERROR_CODE_NO_ERROR) { | ||
| 423 | + // 记录错误日志以及其他业务处理 | ||
| 424 | + } | ||
| 425 | + // 正常业务处理 | ||
| 426 | +} | ||
| 427 | +``` | ||
| 428 | + | ||
| 429 | +### OH_AbilityRuntime_Context_GetCloudFileDir() | ||
| 430 | + | ||
| 431 | +```c | ||
| 432 | +AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetCloudFileDir( | ||
| 433 | + AbilityRuntime_ContextHandle context, char* buffer, const int32_t bufferSize, int32_t* writeLength) | ||
| 434 | +``` | ||
| 435 | + | ||
| 436 | +**描述** | ||
| 437 | + | ||
| 438 | +获取上下文的云文件目录。 | ||
| 439 | + | ||
| 440 | +**起始版本:** 24 | ||
| 441 | + | ||
| 442 | +**参数:** | ||
| 443 | + | ||
| 444 | +| 参数项 | 描述 | | ||
| 445 | +| -- | -- | | ||
| 446 | +| [AbilityRuntime_ContextHandle](capi-abilityruntime-abilityruntime-context8h.md) context | 要获取云文件目录的上下文。 | | ||
| 447 | +| char* buffer | 指向缓冲区的指针,用于接收上下文的云文件目录。 | | ||
| 448 | +| const int32_t bufferSize | 缓冲区大小,单位为字节。 | | ||
| 449 | +| int32_t* writeLength | 在返回[ABILITY_RUNTIME_ERROR_CODE_NO_ERROR](capi-ability-runtime-common-h.md#abilityruntime_errorcode)时,表示实际写入到缓冲区的字符串长度,单位为字节。 | | ||
| 450 | + | ||
| 451 | +**返回:** | ||
| 452 | + | ||
| 453 | +| 类型 | 说明 | | ||
| 454 | +| -- | -- | | ||
| 455 | +| [AbilityRuntime_ErrorCode](capi-ability-runtime-common-h.md#abilityruntime_errorcode) | 返回执行结果。<br>ABILITY_RUNTIME_ERROR_CODE_NO_ERROR - 操作成功。<br>ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID - 入参buffer或writeLength为空或context为空,或缓冲区大小小于需要写入的大小。<br>ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST - 上下文不存在。 | | ||
| 456 | + | ||
| 457 | +**示例代码:** | ||
| 458 | + | ||
| 459 | +```c | ||
| 460 | +#include <AbilityKit/ability_runtime/context.h> | ||
| 461 | + | ||
| 462 | +// 接收一个context 对象 | ||
| 463 | +void testGetCloudFileDir(AbilityRuntime_ContextHandle context) | ||
| 464 | +{ | ||
| 465 | + char buffer[1024] = {0}; | ||
| 466 | + int32_t cloudFileDirSize = 0; | ||
| 467 | + AbilityRuntime_ErrorCode errorCode = ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; | ||
| 468 | + errorCode = OH_AbilityRuntime_Context_GetCloudFileDir(context, buffer, 1024, &cloudFileDirSize); | ||
| 469 | + if (errorCode != ABILITY_RUNTIME_ERROR_CODE_NO_ERROR) { | ||
| 470 | + // 记录错误日志以及其他业务处理 | ||
| 471 | + } | ||
| 472 | + // 正常业务处理 | ||
| 473 | +} | ||
| 474 | +``` | ||
| 475 | + | ||
| 476 | +### OH_AbilityRuntime_Context_GetAreaMode() | ||
| 477 | + | ||
| 478 | +```c | ||
| 479 | +AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetAreaMode( | ||
| 480 | + AbilityRuntime_ContextHandle context, AbilityRuntime_AreaMode* areaMode) | ||
| 481 | +``` | ||
| 482 | + | ||
| 483 | +**描述** | ||
| 484 | + | ||
| 485 | +获取上下文的数据加密等级。 | ||
| 486 | + | ||
| 487 | +**起始版本:** 24 | ||
| 488 | + | ||
| 489 | +**参数:** | ||
| 490 | + | ||
| 491 | +| 参数项 | 描述 | | ||
| 492 | +| -- | -- | | ||
| 493 | +| [AbilityRuntime_ContextHandle](capi-abilityruntime-abilityruntime-context8h.md) context | 要获取数据加密等级的上下文。 | | ||
| 494 | +| [AbilityRuntime_AreaMode](capi-context-constant-h.md#abilityruntime_areamode)* areaMode | 指向接收数据加密等级的指针。 | | ||
| 495 | + | ||
| 496 | +**返回:** | ||
| 497 | + | ||
| 498 | +| 类型 | 说明 | | ||
| 499 | +| -- | -- | | ||
| 500 | +| [AbilityRuntime_ErrorCode](capi-ability-runtime-common-h.md#abilityruntime_errorcode) | 返回执行结果。<br>ABILITY_RUNTIME_ERROR_CODE_NO_ERROR - 操作成功。<br>ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID - 入参areaMode为空。<br>ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST - 上下文不存在。 | | ||
| 501 | + | ||
| 502 | +**示例代码:** | ||
| 503 | + | ||
| 504 | +```c | ||
| 505 | +#include <AbilityKit/ability_runtime/context.h> | ||
| 506 | + | ||
| 507 | +// 接收一个context 对象 | ||
| 508 | +void testGetAreaMode(AbilityRuntime_ContextHandle context) | ||
| 509 | +{ | ||
| 510 | + AbilityRuntime_AreaMode areaMode; | ||
| 511 | + AbilityRuntime_ErrorCode errorCode = ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; | ||
| 512 | + errorCode = OH_AbilityRuntime_Context_GetAreaMode(context, &areaMode); | ||
| 513 | + if (errorCode != ABILITY_RUNTIME_ERROR_CODE_NO_ERROR) { | ||
| 514 | + // 记录错误日志以及其他业务处理 | ||
| 515 | + } | ||
| 516 | + // 正常业务处理 | ||
| 517 | +} | ||
| 518 | +``` | ||
| 519 | + | ||
| 520 | +### OH_AbilityRuntime_Context_SetAreaMode() | ||
| 521 | + | ||
| 522 | +```c | ||
| 523 | +AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_SetAreaMode( | ||
| 524 | + AbilityRuntime_ContextHandle context, AbilityRuntime_AreaMode areaMode) | ||
| 525 | +``` | ||
| 526 | + | ||
| 527 | +**描述** | ||
| 528 | + | ||
| 529 | +设置上下文的数据加密等级。 | ||
| 530 | + | ||
| 531 | +**起始版本:** 24 | ||
| 532 | + | ||
| 533 | +**参数:** | ||
| 534 | + | ||
| 535 | +| 参数项 | 描述 | | ||
| 536 | +| -- | -- | | ||
| 537 | +| [AbilityRuntime_ContextHandle](capi-abilityruntime-abilityruntime-context8h.md) context | 要设置数据加密等级的上下文。 | | ||
| 538 | +| [AbilityRuntime_AreaMode](capi-context-constant-h.md#abilityruntime_areamode) areaMode | 数据加密等级。 | | ||
| 539 | + | ||
| 540 | +**返回:** | ||
| 541 | + | ||
| 542 | +| 类型 | 说明 | | ||
| 543 | +| -- | -- | | ||
| 544 | +| [AbilityRuntime_ErrorCode](capi-ability-runtime-common-h.md#abilityruntime_errorcode) | 返回执行结果。<br>ABILITY_RUNTIME_ERROR_CODE_NO_ERROR - 操作成功。<br>ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID - 入参areaMode为空。<br>ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST - 上下文不存在。 | | ||
| 545 | + | ||
| 546 | +**示例代码:** | ||
| 547 | + | ||
| 548 | +```c | ||
| 549 | +#include <AbilityKit/ability_runtime/context.h> | ||
| 550 | + | ||
| 551 | +// 接收一个context 对象 | ||
| 552 | +void testSetAreaMode(AbilityRuntime_ContextHandle context) | ||
| 553 | +{ | ||
| 554 | + AbilityRuntime_AreaMode areaMode = ABILITY_RUNTIME_AREA_MODE_EL1; | ||
| 555 | + AbilityRuntime_ErrorCode errorCode = ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; | ||
| 556 | + errorCode = OH_AbilityRuntime_Context_SetAreaMode(context, areaMode); | ||
| 557 | + if (errorCode != ABILITY_RUNTIME_ERROR_CODE_NO_ERROR) { | ||
| 558 | + // 记录错误日志以及其他业务处理 | ||
| 559 | + } | ||
| 560 | + // 正常业务处理 | ||
| 561 | +} | ||
| 562 | +``` | ||
| 563 | + | ||
| 564 | +### OH_AbilityRuntime_Context_GetLogFileDir() | ||
| 565 | + | ||
| 566 | +```c | ||
| 567 | +AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetLogFileDir( | ||
| 568 | + AbilityRuntime_ContextHandle context, char* buffer, const int32_t bufferSize, int32_t* writeLength) | ||
| 569 | +``` | ||
| 570 | + | ||
| 571 | +**描述** | ||
| 572 | + | ||
| 573 | +获取上下文的日志文件目录。 | ||
| 574 | + | ||
| 575 | +**起始版本:** 24 | ||
| 576 | + | ||
| 577 | +**参数:** | ||
| 578 | + | ||
| 579 | +| 参数项 | 描述 | | ||
| 580 | +| -- | -- | | ||
| 581 | +| [AbilityRuntime_ContextHandle](capi-abilityruntime-abilityruntime-context8h.md) context | 要获取日志文件目录的上下文。 | | ||
| 582 | +| char* buffer | 指向缓冲区的指针,用于接收上下文的日志文件目录。 | | ||
| 583 | +| const int32_t bufferSize | 缓冲区大小,单位为字节。 | | ||
| 584 | +| int32_t* writeLength | 在返回[ABILITY_RUNTIME_ERROR_CODE_NO_ERROR](capi-ability-runtime-common-h.md#abilityruntime_errorcode)时,表示实际写入到缓冲区的字符串长度,单位为字节。 | | ||
| 585 | + | ||
| 586 | +**返回:** | ||
| 587 | + | ||
| 588 | +| 类型 | 说明 | | ||
| 589 | +| -- | -- | | ||
| 590 | +| [AbilityRuntime_ErrorCode](capi-ability-runtime-common-h.md#abilityruntime_errorcode) | 返回执行结果。<br>ABILITY_RUNTIME_ERROR_CODE_NO_ERROR - 操作成功。<br>ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID - 入参buffer或writeLength为空或context为空,或缓冲区大小小于需要写入的大小。<br>ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST - 上下文不存在。 | | ||
| 591 | + | ||
| 592 | +**示例代码:** | ||
| 593 | + | ||
| 594 | +```c | ||
| 595 | +#include <AbilityKit/ability_runtime/context.h> | ||
| 596 | + | ||
| 597 | +// 接收一个context 对象 | ||
| 598 | +void testGetLogFileDir(AbilityRuntime_ContextHandle context) | ||
| 599 | +{ | ||
| 600 | + char buffer[1024] = {0}; | ||
| 601 | + int32_t logFileDirSize = 0; | ||
| 602 | + AbilityRuntime_ErrorCode errorCode = ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; | ||
| 603 | + errorCode = OH_AbilityRuntime_Context_GetLogFileDir(context, buffer, 1024, &logFileDirSize); | ||
| 604 | + if (errorCode != ABILITY_RUNTIME_ERROR_CODE_NO_ERROR) { | ||
| 605 | + // 记录错误日志以及其他业务处理 | ||
| 606 | + } | ||
| 607 | + // 正常业务处理 | ||
| 608 | +} | ||
| 609 | +``` | ||
| 610 | + | ||
| 611 | +### OH_AbilityRuntime_Context_GetProcessName() | ||
| 612 | + | ||
| 613 | +```c | ||
| 614 | +AbilityRuntime_ErrorCode OH_AbilityRuntime_Context_GetProcessName( | ||
| 615 | + AbilityRuntime_ContextHandle context, char* buffer, int32_t bufferSize, int32_t* writeLength) | ||
| 616 | +``` | ||
| 617 | + | ||
| 618 | +**描述** | ||
| 619 | + | ||
| 620 | +获取上下文所在的进程名称。 | ||
| 621 | + | ||
| 622 | +**起始版本:** 24 | ||
| 623 | + | ||
| 624 | +**参数:** | ||
| 625 | + | ||
| 626 | +| 参数项 | 描述 | | ||
| 627 | +| -- | -- | | ||
| 628 | +| [AbilityRuntime_ContextHandle](capi-abilityruntime-abilityruntime-context8h.md) context | 要获取进程名称的上下文。| | ||
| 629 | +| char* buffer | 指向缓冲区的指针,用于接收进程名称。 | | ||
| 630 | +| int32_t bufferSize | 缓冲区大小,单位为字节。 | | ||
| 631 | +| int32_t* writeLength | 在返回[ABILITY_RUNTIME_ERROR_CODE_NO_ERROR](capi-ability-runtime-common-h.md#abilityruntime_errorcode)时,表示实际写入到缓冲区的字符串长度,单位为字节。 | | ||
| 632 | + | ||
| 633 | +**返回:** | ||
| 634 | + | ||
| 635 | +| 类型 | 说明 | | ||
| 636 | +| -- | -- | | ||
| 637 | +| [AbilityRuntime_ErrorCode](capi-ability-runtime-common-h.md#abilityruntime_errorcode) | 返回执行结果。<br>ABILITY_RUNTIME_ERROR_CODE_NO_ERROR - 操作成功。<br>ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID - 入参buffer或writeLength为空或context为空,或缓冲区大小小于需要写入的大小。<br>ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST - 上下文不存在。 | | ||
| 638 | + | ||
| 639 | +**示例代码:** | ||
| 640 | + | ||
| 641 | +```c | ||
| 642 | +#include <AbilityKit/ability_runtime/context.h> | ||
| 643 | + | ||
| 644 | +// 接收一个context 对象 | ||
| 645 | +void testGetProcessName(AbilityRuntime_ContextHandle context) | ||
| 646 | +{ | ||
| 647 | + char buffer[1024] = {0}; | ||
| 648 | + int32_t processNameSize = 0; | ||
| 649 | + AbilityRuntime_ErrorCode errorCode = ABILITY_RUNTIME_ERROR_CODE_NO_ERROR; | ||
| 650 | + errorCode = OH_AbilityRuntime_Context_GetProcessName(context, buffer, 1024, &processNameSize); | ||
| 651 | + if (errorCode != ABILITY_RUNTIME_ERROR_CODE_NO_ERROR) { | ||
| 652 | + // 记录错误日志以及其他业务处理 | ||
| 653 | + } | ||
| 654 | + // 正常业务处理 | ||
| 655 | +} | ||
| 656 | +``` | ||
| @@ -0,0 +1,93 @@ | |||
| 1 | +# extension_ability.h | ||
| 2 | + | ||
| 3 | +<!--Kit: Ability Kit--> | ||
| 4 | +<!--Subsystem: Ability--> | ||
| 5 | +<!--Owner: @yangzhongkai--> | ||
| 6 | +<!--Designer: @yangzhongkai--> | ||
| 7 | +<!--Tester: @lixueqing513--> | ||
| 8 | +<!--Adviser: @huipeizi--> | ||
| 9 | + | ||
| 10 | +## 概述 | ||
| 11 | + | ||
| 12 | +提供ExtensionAbility回调函数类型声明和入口函数名称声明。 | ||
| 13 | + | ||
| 14 | +**引用文件:** <AbilityKit/ability_runtime/extension_ability.h> | ||
| 15 | + | ||
| 16 | +**库:** libability_runtime.so | ||
| 17 | + | ||
| 18 | +**系统能力:** SystemCapability.Ability.AbilityRuntime.Core | ||
| 19 | + | ||
| 20 | +**起始版本:** 24 | ||
| 21 | + | ||
| 22 | +**相关模块:** [AbilityRuntime](capi-abilityruntime.md) | ||
| 23 | + | ||
| 24 | +## 汇总 | ||
| 25 | + | ||
| 26 | +### 结构体 | ||
| 27 | + | ||
| 28 | +| 名称 | typedef关键字 | 描述 | | ||
| 29 | +| -- | -- | -- | | ||
| 30 | +| [AbilityRuntime_ExtensionInstance](capi-abilityruntime-extensioninstance.md) | - | 定义AbilityRuntime_ExtensionInstance结构体类型。 | | ||
| 31 | +| [AbilityRuntime_ExtensionInstance*](capi-abilityruntime-extensioninstance8h.md) | AbilityRuntime_ExtensionInstanceHandle | 定义指向AbilityRuntime_ExtensionInstance的指针。 | | ||
| 32 | + | ||
| 33 | +### 函数 | ||
| 34 | + | ||
| 35 | +| 名称 | typedef关键字 | 描述 | | ||
| 36 | +| -- | -- | -- | | ||
| 37 | +| [typedef void AbilityRuntime_Extension_CreateFunc(AbilityRuntime_ExtensionInstanceHandle handle, const char *abilityName);](#abilityruntime_extension_createfunc) | AbilityRuntime_Extension_CreateFunc | ExtensionAbility创建回调函数类型。ExtensionAbility中必须实现的回调函数类型,用于实例化ExtensionAbility。| | ||
| 38 | + | ||
| 39 | +### 变量 | ||
![]() ![]() | |||
| 40 | + | ||
| 41 | +| 名称 | 类型 | 描述 | | ||
| 42 | +|------| --- |------| | ||
| 43 | +| [OH_AbilityRuntime_OnNativeExtensionCreate](#oh_abilityruntime_onnativeextensioncreate) | [AbilityRuntime_Extension_CreateFunc](#abilityruntime_extension_createfunc) | ExtensionAbility入口函数名称声明。开发者需要实现一个类型为[AbilityRuntime_Extension_CreateFunc](#abilityruntime_extension_createfunc)的函数,并将其命名为OH_AbilityRuntime_OnNativeExtensionCreate。系统会自动查找并调用此函数来完成ExtensionAbility实例的初始化。<br>**起始版本:** 24 | | ||
| 44 | + | ||
| 45 | +## 函数说明 | ||
| 46 | + | ||
| 47 | +### AbilityRuntime_Extension_CreateFunc() | ||
| 48 | + | ||
| 49 | +```c | ||
| 50 | +typedef void AbilityRuntime_Extension_CreateFunc(AbilityRuntime_ExtensionInstanceHandle handle, const char *abilityName) | ||
| 51 | +``` | ||
| 52 | + | ||
| 53 | +**描述** | ||
| 54 | + | ||
| 55 | +ExtensionAbility创建回调函数类型。ExtensionAbility中必须实现的回调函数类型,用于实例化ExtensionAbility。 | ||
| 56 | + | ||
| 57 | +**起始版本:** 24 | ||
| 58 | + | ||
| 59 | +**参数:** | ||
| 60 | + | ||
| 61 | +| 参数名 | 描述 | | ||
| 62 | +|--------|------| | ||
| 63 | +| [AbilityRuntime_ExtensionInstanceHandle](capi-abilityruntime-extensioninstance8h.md) handle | 回调函数传入AbilityRuntime_ExtensionInstanceHandle实例的指针。 | | ||
| 64 | +| const char *abilityName | 回调函数传入的ExtensionAbility的名称。 | | ||
| 65 | + | ||
| 66 | +## 变量说明 | ||
| 67 | + | ||
| 68 | +### OH_AbilityRuntime_OnNativeExtensionCreate | ||
| 69 | + | ||
| 70 | +```c | ||
| 71 | +AbilityRuntime_Extension_CreateFunc OH_AbilityRuntime_OnNativeExtensionCreate | ||
| 72 | +``` | ||
| 73 | + | ||
| 74 | +**描述** | ||
| 75 | + | ||
| 76 | +ExtensionAbility入口函数名称声明。开发者需要实现一个类型为[AbilityRuntime_Extension_CreateFunc](#abilityruntime_extension_createfunc)的函数,并将其命名为OH_AbilityRuntime_OnNativeExtensionCreate。系统会自动查找并调用此函数来完成ExtensionAbility实例的初始化。 | ||
| 77 | + | ||
| 78 | +**起始版本:** 24 | ||
| 79 | + | ||
| 80 | +**示例代码:** | ||
| 81 | + | ||
| 82 | +```c | ||
| 83 | +#include <AbilityKit/ability_runtime/extension_ability.h> | ||
| 84 | + | ||
| 85 | +extern "C" void OH_AbilityRuntime_OnNativeExtensionCreate(AbilityRuntime_ExtensionInstance *instance, | ||
| 86 | + const char *abilityName) { | ||
| 87 | + if (!instance) { | ||
| 88 | + // 记录错误日志以及其他业务处理 | ||
| 89 | + return; | ||
| 90 | + } | ||
| 91 | + // ExtensionAbility 初始化工作 | ||
| 92 | +} | ||
| 93 | +``` | ||



新增节点在readme中增加一下 下同