mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-30 10:52:57 +00:00
Description: add application context ndk
IssueNo: Sig: SIG_ApplicationFramework Feature or Bugfix: Feature Binary Source: No Signed-off-by: yangzk <yangzhongkai@huawei.com> Change-Id: If4888aba7774112d431924dfbf55dc77ee594beb
This commit is contained in:
parent
898561e46a
commit
8c63878362
12
bundle.json
12
bundle.json
@ -112,6 +112,7 @@
|
||||
"//foundation/ability/ability_runtime/frameworks/native/ability/native:extension_module",
|
||||
"//foundation/ability/ability_runtime/frameworks/native/child_process:child_process",
|
||||
"//foundation/ability/ability_runtime/frameworks/native/insight_intent:insight_intent_innerkits",
|
||||
"//foundation/ability/ability_runtime/frameworks/c/ability_runtime:ability_runtime",
|
||||
"//foundation/ability/ability_runtime/frameworks/cj:cj_ability_packages",
|
||||
"//foundation/ability/ability_runtime/frameworks/js/napi:napi_packages",
|
||||
"//foundation/ability/ability_runtime/cj_environment/frameworks/cj_environment:cj_environment",
|
||||
@ -329,6 +330,17 @@
|
||||
},
|
||||
"name": "//foundation/ability/ability_runtime/frameworks/native/child_process:child_process"
|
||||
},
|
||||
{
|
||||
"header": {
|
||||
"header_base": "//foundation/ability/ability_runtime/interfaces/kits/c/ability_runtime",
|
||||
"header_files": [
|
||||
"ability_runtime_common.h",
|
||||
"application_context.h",
|
||||
"context_constant.h"
|
||||
]
|
||||
},
|
||||
"name": "//foundation/ability/ability_runtime/frameworks/c/ability_runtime:ability_runtime"
|
||||
},
|
||||
{
|
||||
"header": {
|
||||
"header_base": "//foundation/ability/ability_runtime/interfaces/inner_api/uri_permission/include/",
|
||||
|
62
frameworks/c/ability_runtime/BUILD.gn
Normal file
62
frameworks/c/ability_runtime/BUILD.gn
Normal file
@ -0,0 +1,62 @@
|
||||
# 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("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
|
||||
config("ability_runtime_ndk_config") {
|
||||
include_dirs = [
|
||||
"${ability_runtime_ndk_path}",
|
||||
"${ability_runtime_ndk_path}/ability_runtime",
|
||||
]
|
||||
|
||||
if (target_cpu == "arm") {
|
||||
cflags = [ "-DBINDER_IPC_32BIT" ]
|
||||
}
|
||||
}
|
||||
|
||||
ohos_shared_library("ability_runtime") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
cfi_vcall_icall_only = true
|
||||
debug = false
|
||||
}
|
||||
branch_protector_ret = "pac_ret"
|
||||
|
||||
include_dirs = [
|
||||
"include",
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/",
|
||||
]
|
||||
|
||||
configs = [ "${ability_runtime_services_path}/common:common_config" ]
|
||||
public_configs = [ ":ability_runtime_ndk_config" ]
|
||||
|
||||
sources = [ "src/application_context.cpp" ]
|
||||
|
||||
deps = [ "${ability_runtime_native_path}/appkit:app_context" ]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
]
|
||||
|
||||
output_extension = "so"
|
||||
innerapi_tags = [ "ndk" ]
|
||||
install_images = [ "system" ]
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
}
|
108
frameworks/c/ability_runtime/src/application_context.cpp
Normal file
108
frameworks/c/ability_runtime/src/application_context.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "application_context.h"
|
||||
|
||||
#include "context.h"
|
||||
#include "context/application_context.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
|
||||
using namespace OHOS::AbilityRuntime;
|
||||
|
||||
namespace {
|
||||
AbilityRuntime_ErrorCode WriteStringToBuffer(
|
||||
const std::string &src, char* buffer, const int32_t bufferSize, int32_t* writeLength)
|
||||
{
|
||||
const auto srcLength = static_cast<int32_t>(src.length());
|
||||
if (bufferSize - 1 < srcLength) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "the buffer size is less than the minimum buffer size");
|
||||
return ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID;
|
||||
}
|
||||
src.copy(buffer, srcLength);
|
||||
buffer[srcLength] = '\0';
|
||||
*writeLength = srcLength;
|
||||
return ABILITY_RUNTIME_ERROR_CODE_NO_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetCacheDir(
|
||||
char* buffer, const int32_t bufferSize, int32_t* writeLength)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "called");
|
||||
if (buffer == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "buffer is null");
|
||||
return ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID;
|
||||
}
|
||||
if (writeLength == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "writeLength is null");
|
||||
return ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID;
|
||||
}
|
||||
|
||||
const auto appContext = Context::GetApplicationContext();
|
||||
if (appContext == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "appContext is null");
|
||||
return ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID;
|
||||
}
|
||||
const std::string cacheDir = appContext->GetCacheDir();
|
||||
if (cacheDir.empty()) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "cacheDir is empty");
|
||||
return ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID;
|
||||
}
|
||||
return WriteStringToBuffer(cacheDir, buffer, bufferSize, writeLength);
|
||||
}
|
||||
|
||||
AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetAreaMode(AbilityRuntime_AreaMode* areaMode)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "called");
|
||||
if (areaMode == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "areaMode is null");
|
||||
return ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID;
|
||||
}
|
||||
|
||||
const auto appContext = Context::GetApplicationContext();
|
||||
if (appContext == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "appContext is null");
|
||||
return ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID;
|
||||
}
|
||||
int32_t area = appContext->GetArea();
|
||||
*areaMode = static_cast<AbilityRuntime_AreaMode>(area);
|
||||
return ABILITY_RUNTIME_ERROR_CODE_NO_ERROR;
|
||||
}
|
||||
|
||||
AbilityRuntime_ErrorCode OH_AbilityRuntime_ApplicationContextGetBundleName(
|
||||
char* buffer, const int32_t bufferSize, int32_t* writeLength)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPKIT, "called");
|
||||
if (buffer == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "buffer is null");
|
||||
return ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID;
|
||||
}
|
||||
if (writeLength == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "writeLength is null");
|
||||
return ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID;
|
||||
}
|
||||
|
||||
const auto appContext = Context::GetApplicationContext();
|
||||
if (appContext == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "appContext is null");
|
||||
return ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID;
|
||||
}
|
||||
const std::string bundleName = appContext->GetBundleName();
|
||||
if (bundleName.empty()) {
|
||||
TAG_LOGE(AAFwkTag::APPKIT, "bundleName is empty");
|
||||
return ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID;
|
||||
}
|
||||
return WriteStringToBuffer(bundleName, buffer, bufferSize, writeLength);
|
||||
}
|
@ -302,7 +302,6 @@ ohos_shared_library("app_context") {
|
||||
|
||||
external_deps = [
|
||||
"ability_base:extractortool",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"hilog:libhilog",
|
||||
@ -319,6 +318,7 @@ ohos_shared_library("app_context") {
|
||||
"ability_base:session_info",
|
||||
"ability_base:want",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
]
|
||||
|
||||
if (ability_runtime_graphics) {
|
||||
|
61
interfaces/kits/c/ability_runtime/ability_runtime_common.h
Normal file
61
interfaces/kits/c/ability_runtime/ability_runtime_common.h
Normal file
@ -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
|
97
interfaces/kits/c/ability_runtime/application_context.h
Normal file
97
interfaces/kits/c/ability_runtime/application_context.h
Normal file
@ -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 <stdint.h>
|
||||
#include <stddef.h>
|
||||
#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
|
82
interfaces/kits/c/ability_runtime/context_constant.h
Normal file
82
interfaces/kits/c/ability_runtime/context_constant.h
Normal file
@ -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
|
@ -31,6 +31,7 @@ config("common_config") {
|
||||
"${ability_runtime_napi_path}/*",
|
||||
"${ability_runtime_native_path}/ability/native/*",
|
||||
"${ability_runtime_native_path}/child_process/*",
|
||||
"${ability_runtime_path}/frameworks/c/ability_runtime/*",
|
||||
"${ability_runtime_path}/frameworks/simulator/ability_simulator/*",
|
||||
"${ability_runtime_path}/tools/aa/*",
|
||||
"${ability_runtime_services_path}/common/*",
|
||||
|
Loading…
Reference in New Issue
Block a user