From c72e763c49f9dfca4b1cf430d95f50c84b294593 Mon Sep 17 00:00:00 2001 From: yangzk Date: Fri, 30 Aug 2024 18:10:36 +0800 Subject: [PATCH 1/2] Description: add application context ndk IssueNo: Sig: SIG_ApplicationFramework Feature or Bugfix: Feature Binary Source: No Signed-off-by: yangzk Change-Id: If4888aba7774112d431924dfbf55dc77ee594beb --- AbilityKit/ability_runtime/BUILD.gn | 36 +++++++ .../ability_runtime/ability_runtime_common.h | 61 ++++++++++++ .../ability_runtime/application_context.h | 97 +++++++++++++++++++ AbilityKit/ability_runtime/context_constant.h | 82 ++++++++++++++++ .../libability_runtime.ndk.json | 14 +++ 5 files changed, 290 insertions(+) create mode 100644 AbilityKit/ability_runtime/BUILD.gn create mode 100644 AbilityKit/ability_runtime/ability_runtime_common.h create mode 100644 AbilityKit/ability_runtime/application_context.h create mode 100644 AbilityKit/ability_runtime/context_constant.h create mode 100644 AbilityKit/ability_runtime/libability_runtime.ndk.json diff --git a/AbilityKit/ability_runtime/BUILD.gn b/AbilityKit/ability_runtime/BUILD.gn new file mode 100644 index 000000000..e96e8afc2 --- /dev/null +++ b/AbilityKit/ability_runtime/BUILD.gn @@ -0,0 +1,36 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/ohos/ndk/ndk.gni") +ohos_ndk_headers("ability_runtime_ndk_header") { + dest_dir = "$ndk_headers_out_dir/AbilityKit/ability_runtime" + sources = [ + "./ability_runtime_common.h", + "./application_context.h", + "./context_constant.h", + ] +} + +ohos_ndk_library("libability_runtime") { + output_name = "ability_runtime" + output_extension = "so" + system_capability = "SystemCapability.Ability.AbilityRuntime.Core" + ndk_description_file = "./libability_runtime.ndk.json" + min_compact_version = "13" + system_capability_headers = [ + "AbilityKit/ability_runtime/ability_runtime_common.h", + "AbilityKit/ability_runtime/application_context.h", + "AbilityKit/ability_runtime/context_constant.h", + ] +} diff --git a/AbilityKit/ability_runtime/ability_runtime_common.h b/AbilityKit/ability_runtime/ability_runtime_common.h new file mode 100644 index 000000000..d6220b080 --- /dev/null +++ b/AbilityKit/ability_runtime/ability_runtime_common.h @@ -0,0 +1,61 @@ +/* +* Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup AbilityRuntime + * @{ + * + * @brief Provide the definition of the C interface for the native AbilityRuntime + * + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @since 13 + */ + +/** + * @file ability_runtime_common.h + * + * @brief Declare the common types for the native AbilityRuntime. + * + * @library libability_runtime.so + * @kit AbilityKit + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @since 13 + */ + +#ifndef ABILITY_RUNTIME_COMMON_H +#define ABILITY_RUNTIME_COMMON_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Enumerates the error codes. + * + * @since 13 + */ +typedef enum { + /** @error No error. */ + ABILITY_RUNTIME_ERROR_CODE_NO_ERROR = 0, + /** @error Invalid parameters. */ + ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID = 401, +} AbilityRuntime_ErrorCode; + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif //ABILITY_RUNTIME_COMMON_H diff --git a/AbilityKit/ability_runtime/application_context.h b/AbilityKit/ability_runtime/application_context.h new file mode 100644 index 000000000..374a99bd8 --- /dev/null +++ b/AbilityKit/ability_runtime/application_context.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup AbilityRuntime + * @{ + * + * @brief Describe the functions provided by the application context. + * + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @since 13 + */ + +/** + * @file application_context.h + * + * @brief Defines the application context APIs. + * + * @library libability_runtime.so + * @kit AbilityKit + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @since 13 + */ + +#ifndef ABILITY_RUNTIME_APPLICATION_CONTEXT_H +#define ABILITY_RUNTIME_APPLICATION_CONTEXT_H + +#include +#include +#include "ability_runtime_common.h" +#include "context_constant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Obtain the cache directory of the application. + * + * @param buffer A pointer to a buffer that receives the cache directory of the application. + * @param bufferSize The length of the buffer. + * @param writeLength The string length actually written to the buffer, + * when returning {@link ABILITY_RUNTIME_ERROR_CODE_NO_ERROR}. + * @return The error code. + * {@link ABILITY_RUNTIME_ERROR_CODE_NO_ERROR} if the operation is successful. + * {@link ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID} if the buffer or writeLength is null, + * or the buffer size is less than the minimum buffer size. + * @since 13 + */ +AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetCacheDir( + char* buffer, int32_t bufferSize, int32_t* writeLength); + +/** + * @brief Obtain the area mode of the application. + * + * @param areaMode A pointer to the area mode. + * @return The error code. + * {@link ABILITY_RUNTIME_ERROR_CODE_NO_ERROR} if the operation is successful. + * {@link ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID} if the areaMode is null. + * @since 13 + */ +AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetAreaMode(AbilityRuntime_AreaMode* areaMode); + +/** + * @brief Obtain the bundle name. + * + * @param buffer A pointer to a buffer that receives the bundle name. + * @param bufferSize The length of the buffer. + * @param writeLength The string length actually written to the buffer, + * when returning {@link ABILITY_RUNTIME_ERROR_CODE_NO_ERROR}. + * @return The error code. + * {@link ABILITY_RUNTIME_ERROR_CODE_NO_ERROR} if the operation is successful. + * {@link ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID} if the buffer or writeLength is null, + * or the buffer size is less than the minimum buffer size. + * @since 13 + */ +AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetBundleName( + char* buffer, int32_t bufferSize, int32_t* writeLength); + +#ifdef __cplusplus +} // extern "C" +#endif + +/** @} */ +#endif // ABILITY_RUNTIME_APPLICATION_CONTEXT_H diff --git a/AbilityKit/ability_runtime/context_constant.h b/AbilityKit/ability_runtime/context_constant.h new file mode 100644 index 000000000..921f407c1 --- /dev/null +++ b/AbilityKit/ability_runtime/context_constant.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup AbilityRuntime + * @{ + * + * @brief Describe the constant of context. + * + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @since 13 + */ + +/** + * @file context_constant.h + * + * @brief Defines the constant of context. + * + * @library libability_runtime.so + * @kit AbilityKit + * @syscap SystemCapability.Ability.AbilityRuntime.Core + * @since 13 + */ + +#ifndef ABILITY_RUNTIME_CONTEXT_CONSTANT_H +#define ABILITY_RUNTIME_CONTEXT_CONSTANT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief File area mode. + * + * @since 13 + */ +typedef enum { + /** + * System level device encryption area. + */ + ABILITY_RUNTIME_AREA_MODE_EL1 = 0, + /** + * User credential encryption area. + */ + ABILITY_RUNTIME_AREA_MODE_EL2 = 1, + /** + * User credential encryption area. + * when screen locked, can read/write, and create file. + */ + ABILITY_RUNTIME_AREA_MODE_EL3 = 2, + /** + * User credential encryption area. + * when screen locked, FEB2.0 can read/write, FEB3.0 can't + * read/write, and all can't create file. + */ + ABILITY_RUNTIME_AREA_MODE_EL4 = 3, + /** + * User privacy-sensitive encryption area. + * when the screen locked, a closed file cannot be opened, read, or written, + * a file can be created and then opened, read, or written. + */ + ABILITY_RUNTIME_AREA_MODE_EL5 = 4, +} AbilityRuntime_AreaMode; + +#ifdef __cplusplus +} // extern "C" +#endif + +/** @} */ +#endif // ABILITY_RUNTIME_CONTEXT_CONSTANT_H diff --git a/AbilityKit/ability_runtime/libability_runtime.ndk.json b/AbilityKit/ability_runtime/libability_runtime.ndk.json new file mode 100644 index 000000000..239f84f61 --- /dev/null +++ b/AbilityKit/ability_runtime/libability_runtime.ndk.json @@ -0,0 +1,14 @@ +[ + { + "first_introduced": "13", + "name": "OH_AbilityRuntime_ApplicationContextGetCacheDir" + }, + { + "first_introduced": "13", + "name": "OH_AbilityRuntime_ApplicationContextGetAreaMode" + }, + { + "first_introduced": "13", + "name": "OH_AbilityRuntime_ApplicationContextGetBundleName" + } +] \ No newline at end of file -- Gitee From d69ca7412abc3c9e5cba6e30c716215bb89887d7 Mon Sep 17 00:00:00 2001 From: yangzk Date: Sun, 8 Sep 2024 17:18:49 +0800 Subject: [PATCH 2/2] =?UTF-8?q?Description:=20=E6=96=B0=E5=A2=9Eapplicatio?= =?UTF-8?q?nContext=E9=94=99=E8=AF=AF=E7=A0=81ABILITY=5FRUNTIME=5FERROR=5F?= =?UTF-8?q?CODE=5FCONTEXT=5FNOT=5FEXIST=20IssueNo:=20#IAPOX6=20Sig:=20SIG?= =?UTF-8?q?=5FApplicationFramework=20Feature=20or=20Bugfix:=20Bugfix=20Bin?= =?UTF-8?q?ary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangzk Change-Id: I25509e923f6ebaeffaec07ee0bdc852b60762ee5 --- AbilityKit/ability_runtime/ability_runtime_common.h | 4 +++- AbilityKit/ability_runtime/application_context.h | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/AbilityKit/ability_runtime/ability_runtime_common.h b/AbilityKit/ability_runtime/ability_runtime_common.h index d6220b080..e4cf556e4 100644 --- a/AbilityKit/ability_runtime/ability_runtime_common.h +++ b/AbilityKit/ability_runtime/ability_runtime_common.h @@ -51,6 +51,8 @@ typedef enum { ABILITY_RUNTIME_ERROR_CODE_NO_ERROR = 0, /** @error Invalid parameters. */ ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID = 401, + /** @error The context does not exist. */ + ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST = 16000011, } AbilityRuntime_ErrorCode; #ifdef __cplusplus @@ -58,4 +60,4 @@ typedef enum { #endif /** @} */ -#endif //ABILITY_RUNTIME_COMMON_H +#endif // ABILITY_RUNTIME_COMMON_H diff --git a/AbilityKit/ability_runtime/application_context.h b/AbilityKit/ability_runtime/application_context.h index 374a99bd8..1ba53503d 100644 --- a/AbilityKit/ability_runtime/application_context.h +++ b/AbilityKit/ability_runtime/application_context.h @@ -57,6 +57,7 @@ extern "C" { * {@link ABILITY_RUNTIME_ERROR_CODE_NO_ERROR} if the operation is successful. * {@link ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID} if the buffer or writeLength is null, * or the buffer size is less than the minimum buffer size. + * {@link ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST} if the application context does not exist. * @since 13 */ AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetCacheDir( @@ -69,6 +70,7 @@ AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetCacheDir( * @return The error code. * {@link ABILITY_RUNTIME_ERROR_CODE_NO_ERROR} if the operation is successful. * {@link ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID} if the areaMode is null. + * {@link ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST} if the application context does not exist. * @since 13 */ AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetAreaMode(AbilityRuntime_AreaMode* areaMode); @@ -84,6 +86,7 @@ AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetAreaMode(Ability * {@link ABILITY_RUNTIME_ERROR_CODE_NO_ERROR} if the operation is successful. * {@link ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID} if the buffer or writeLength is null, * or the buffer size is less than the minimum buffer size. + * {@link ABILITY_RUNTIME_ERROR_CODE_CONTEXT_NOT_EXIST} if the application context does not exist. * @since 13 */ AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetBundleName( -- Gitee