From 30e8efc4c08b907b91d7e3baf2d4d5d52fcceb11 Mon Sep 17 00:00:00 2001 From: yangzk Date: Fri, 30 Aug 2024 18:10:36 +0800 Subject: [PATCH] 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