reset 0328code to 0702

Signed-off-by: cat <chenjinxiang3@huawei.com>
This commit is contained in:
cat
2025-07-08 15:47:25 +08:00
parent 2b0fa6360f
commit 4ca3c3748e
6 changed files with 332 additions and 2 deletions
+4 -2
View File
@@ -27,13 +27,15 @@
"components": [
"napi",
"bounds_checking_function",
"cJSON"
"cJSON",
"runtime_core"
],
"third_party": []
},
"build": {
"sub_component": [
"//developtools/syscap_codec:syscap_codec"
"//developtools/syscap_codec:syscap_codec",
"//developtools/syscap_codec/taihe:taihe_group"
],
"inner_kits": [
{
+23
View File
@@ -0,0 +1,23 @@
# Copyright (c) 2025 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("//developtools/syscap_codec/config.gni")
group("taihe_group") {
if (support_jsapi) {
deps = [
"syscap:systemCapability_etc",
"syscap:systemCapability_taihe_native",
]
}
}
+86
View File
@@ -0,0 +1,86 @@
# Copyright (c) 2025 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/config/components/ets_frontend/ets2abc_config.gni")
import("//build/ohos.gni")
import("//build/ohos/taihe_idl/taihe.gni")
copy_taihe_idl("copy_systemCapability") {
sources = [ "idl/ohos.systemCapability.taihe" ]
}
subsystem_name = "developtools"
part_name = "syscap_codec"
taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name"
ohos_taihe("run_taihe") {
taihe_generated_file_path = "$taihe_generated_file_path"
deps = [ ":copy_systemCapability" ]
outputs = [
"$taihe_generated_file_path/src/ohos.systemCapability.ani.cpp",
"$taihe_generated_file_path/src/ohos.systemCapability.abi.c",
]
}
taihe_shared_library("systemCapability_taihe_native") {
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
}
taihe_generated_file_path = "$taihe_generated_file_path"
part_name = "$part_name"
subsystem_name = "$subsystem_name"
sources = get_target_outputs(":run_taihe")
include_dirs = [
"../../src",
"../../interfaces/inner_api",
"../../include",
"../../include/codec_config"
]
sources += [
"src/ani_constructor.cpp",
"src/ohos.systemCapability.impl.cpp",
"../../src/syscap_tool.c",
"../../src/create_pcid.c",
"../../src/endian_internal.c",
"../../src/common_method.c",
"../../src/context_tool.c",
"../../interfaces/inner_api/syscap_interface.c",
]
deps = [
":run_taihe",
]
external_deps = [
"bounds_checking_function:libsec_shared",
]
if (defined(ohos_lite)) {
deps += [ "//build/lite/config/component/cJSON:cjson_static" ]
} else {
external_deps += [ "cJSON:cjson_static" ]
}
}
generate_static_abc("systemCapability") {
base_url = "$taihe_generated_file_path"
files = [ "$taihe_generated_file_path/@ohos.systemCapability.ets" ]
is_boot_abc = "True"
device_dst_file = "/system/framework/systemCapability.abc"
dependencies = [ ":run_taihe" ]
}
ohos_prebuilt_etc("systemCapability_etc") {
source = "$target_out_dir/systemCapability.abc"
module_install_dir = "framework"
part_name = "$part_name"
subsystem_name = "$subsystem_name"
deps = [ ":systemCapability" ]
}
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2025 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.
*/
@!namespace("@ohos.systemCapability", "systemCapability")
@!sts_inject("""
static { loadLibrary("systemCapability_taihe_native.z") }
""")
@gen_async("querySystemCapabilities")
@gen_promise("querySystemCapabilities")
function querySystemCapabilitie(): String;
+29
View File
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2025 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 "taihe/runtime.hpp"
#include "ohos.systemCapability.ani.hpp"
ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result)
{
ani_env *env;
if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) {
return ANI_ERROR;
}
if (ANI_OK != ohos::systemCapability::ANIRegister(env)) {
std::cerr << "Error from ohos::systemCapability::ANIRegister" << std::endl;
return ANI_ERROR;
}
*result = ANI_VERSION_1;
return ANI_OK;
}
@@ -0,0 +1,167 @@
/*
* Copyright (c) 2025 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 "ohos.systemCapability.proj.hpp"
#include "ohos.systemCapability.impl.hpp"
#include "taihe/runtime.hpp"
#include "stdexcept"
#include <cstdint>
#include <cstring>
#include <cstdlib>
#include <securec.h>
#include "syscap_interface.h"
#include "context_tool.h"
using namespace taihe;
namespace {
// To be implemented.
constexpr size_t OS_SYSCAP_U32_NUM = 30;
constexpr size_t PCID_MAIN_U32 = OS_SYSCAP_U32_NUM + 2;
constexpr size_t U32_TO_STR_MAX_LEN = 11;
constexpr size_t KEY_BUFFER_SIZE = 32;
struct SystemCapabilityAsyncContext {
char key[KEY_BUFFER_SIZE] = { 0 };
size_t keyLen = 0;
char *value = nullptr;
size_t valueLen = 0;
int status = 0;
};
static char* CalculateAllStringLength(char osCapArray[PCID_MAIN_U32][U32_TO_STR_MAX_LEN],
char (*priCapArray)[SINGLE_SYSCAP_LEN], bool retBool, int priCapArrayCnt)
{
errno_t err = EOK;
char *temp = nullptr;
int retError;
int sumLen = 0;
char *allSyscapBuffer = nullptr;
if (!retBool) {
PRINT_ERR("get encoded private syscap failed.");
return allSyscapBuffer;
}
for (size_t i = 0; i < PCID_MAIN_U32; i++) {
sumLen += strlen(osCapArray[i]);
}
for (int i = 0; i < priCapArrayCnt; i++) {
sumLen += strlen(*(priCapArray + i));
}
sumLen += (PCID_MAIN_U32 + priCapArrayCnt + 1); // split with ','
// splicing string
allSyscapBuffer = (char *)malloc(sumLen);
if (allSyscapBuffer == nullptr) {
PRINT_ERR("malloc failed!");
return allSyscapBuffer;
}
err = memset_s(allSyscapBuffer, sumLen, 0, sumLen);
if (err != EOK) {
PRINT_ERR("memset failed!");
free(allSyscapBuffer);
return nullptr;
}
temp = *osCapArray;
for (size_t i = 1; i < PCID_MAIN_U32; i++) {
retError = sprintf_s(allSyscapBuffer, sumLen, "%s,%s", temp, osCapArray[i]);
if (retError == -1) {
PRINT_ERR("splicing os syscap string failed.");
free(allSyscapBuffer);
return nullptr;
}
temp = allSyscapBuffer;
}
for (int i = 0; i < priCapArrayCnt; i++) {
retError = sprintf_s(allSyscapBuffer, sumLen, "%s,%s", temp, *(priCapArray + i));
if (retError == -1) {
PRINT_ERR("splicing pri syscap string failed.");
free(allSyscapBuffer);
return nullptr;
}
temp = allSyscapBuffer;
}
return allSyscapBuffer;
}
static char* GetSystemCapability()
{
bool retBool;
int retError;
int priOutputLen;
int priCapArrayCnt;
char osOutput[SINGLE_SYSCAP_LEN] = {};
uint32_t *osCapU32 = nullptr;
char *priOutput = nullptr;
char *allSyscapBuffer = nullptr;
char osCapArray[PCID_MAIN_U32][U32_TO_STR_MAX_LEN] = {};
char (*priCapArray)[SINGLE_SYSCAP_LEN] = nullptr;
retBool = EncodeOsSyscap(osOutput, PCID_MAIN_BYTES);
if (!retBool) {
PRINT_ERR("get encoded os syscap failed.");
return nullptr;
}
retBool = EncodePrivateSyscap(&priOutput, &priOutputLen);
if (!retBool) {
PRINT_ERR("get encoded private syscap failed.");
goto FREE_PRIOUTPUT;
}
osCapU32 = reinterpret_cast<uint32_t *>(osOutput);
for (size_t i = 0; i < PCID_MAIN_U32; i++) { // 2, header of pcid.sc
retError = sprintf_s(osCapArray[i], U32_TO_STR_MAX_LEN, "%u", osCapU32[i]);
if (retError == -1) {
PRINT_ERR("get uint32_t syscap string failed.");
goto FREE_PRIOUTPUT;
}
}
retBool = DecodePrivateSyscap(priOutput, &priCapArray, &priCapArrayCnt);
allSyscapBuffer = CalculateAllStringLength(osCapArray, priCapArray, retBool, priCapArrayCnt);
free(priCapArray);
FREE_PRIOUTPUT:
free(priOutput);
return allSyscapBuffer;
}
string querySystemCapabilitie()
{
SystemCapabilityAsyncContext *asyncContext = new SystemCapabilityAsyncContext();
char *syscapStr = GetSystemCapability();
if (syscapStr != nullptr) {
asyncContext->value = syscapStr;
asyncContext->status = 0;
} else {
asyncContext->status = 1;
}
string value = "";
if (!asyncContext->status) {
value = asyncContext->value;
} else {
taihe::set_business_error(-1, "key does not exist");
}
return value;
}
} // namespace
// Since these macros are auto-generate, lint will cause false positive.
// NOLINTBEGIN
TH_EXPORT_CPP_API_querySystemCapabilitie(querySystemCapabilitie);
// NOLINTEND