From fcda5db573c0d8ccad9fad6f99bae963df64bb7b Mon Sep 17 00:00:00 2001 From: donglin Date: Tue, 9 Apr 2024 09:38:12 +0000 Subject: [PATCH] system_kit Signed-off-by: donglin Change-Id: If78b30a73565ec3c6961e57437066040def30615 --- frameworks/native/runtime/js_runtime.cpp | 17 +++++++++++++++-- interfaces/inner_api/runtime/BUILD.gn | 1 + .../inner_api/runtime/include/js_runtime.h | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/frameworks/native/runtime/js_runtime.cpp b/frameworks/native/runtime/js_runtime.cpp index 433d612aaf..22ad66eca5 100644 --- a/frameworks/native/runtime/js_runtime.cpp +++ b/frameworks/native/runtime/js_runtime.cpp @@ -26,6 +26,7 @@ #include #include "accesstoken_kit.h" +#include "config_policy_utils.h" #include "constants.h" #include "connect_server_manager.h" #include "ecmascript/napi/include/jsnapi.h" @@ -85,6 +86,7 @@ constexpr char MERGE_ABC_PATH[] = "/ets/modules.abc"; constexpr char BUNDLE_INSTALL_PATH[] = "/data/storage/el1/bundle/"; constexpr const char* PERMISSION_RUN_ANY_CODE = "ohos.permission.RUN_ANY_CODE"; +const std::string CONFIG_PATH = "/etc/system_kits_config.json"; const std::string SYSTEM_KITS_CONFIG_PATH = "/system/etc/system_kits_config.json"; const std::string SYSTEM_KITS = "systemkits"; @@ -1476,18 +1478,29 @@ void JsRuntime::SetDeviceDisconnectCallback(const std::function &cb) jsEnv_->SetDeviceDisconnectCallback(cb); } +std::string JsRuntime::GetSystemKitPath() +{ + char buf[MAX_PATH_LEN] = { 0 }; + char *configPath = GetOneCfgFile(CONFIG_PATH.c_str(), buf, MAX_PATH_LEN); + if (configPath == nullptr || configPath[0] == '\0' || strlen(configPath) > MAX_PATH_LEN) { + return SYSTEM_KITS_CONFIG_PATH; + } + return configPath; +} + std::vector JsRuntime::GetSystemKitsMap(uint32_t version) { std::vector systemKitsMap; nlohmann::json jsonBuf; - if (access(SYSTEM_KITS_CONFIG_PATH.c_str(), F_OK) != 0) { + std::string configPath = GetSystemKitPath(); + if (configPath == "") { return systemKitsMap; } std::fstream in; char errBuf[256]; errBuf[0] = '\0'; - in.open(SYSTEM_KITS_CONFIG_PATH, std::ios_base::in); + in.open(configPath, std::ios_base::in); if (!in.is_open()) { strerror_r(errno, errBuf, sizeof(errBuf)); return systemKitsMap; diff --git a/interfaces/inner_api/runtime/BUILD.gn b/interfaces/inner_api/runtime/BUILD.gn index 726682be36..a34464ce16 100644 --- a/interfaces/inner_api/runtime/BUILD.gn +++ b/interfaces/inner_api/runtime/BUILD.gn @@ -103,6 +103,7 @@ ohos_shared_library("runtime") { "bundle_framework:bundle_napi_common", "bundle_framework:libappexecfwk_common", "c_utils:utils", + "config_policy:configpolicy_util", "ets_runtime:libark_jsruntime", "ets_utils:console", "ets_utils:timer", diff --git a/interfaces/inner_api/runtime/include/js_runtime.h b/interfaces/inner_api/runtime/include/js_runtime.h index 6056819e7d..7dafbfd4a4 100644 --- a/interfaces/inner_api/runtime/include/js_runtime.h +++ b/interfaces/inner_api/runtime/include/js_runtime.h @@ -176,6 +176,7 @@ private: void LoadAotFile(const Options& options); void SetRequestAotCallback(); + std::string GetSystemKitPath(); std::vector GetSystemKitsMap(uint32_t version); }; } // namespace AbilityRuntime