From c85309fbbaebcb487cdf3fc0b413030c233f009d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=BB=E5=9B=BD=E5=86=9B?= Date: Tue, 17 Mar 2026 16:36:34 +0800 Subject: [PATCH] add SetOrUpdateLibPath MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 任国军 --- frameworks/native/appkit/app/main_thread.cpp | 8 ++++-- frameworks/native/runtime/js_runtime.cpp | 25 +++++++++++++++++++ .../inner_api/runtime/include/js_runtime.h | 1 + .../unittest/runtime_test/js_runtime_test.cpp | 21 ++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 28bd5acb53..bfa17b285d 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -2397,9 +2397,13 @@ void MainThread::DoUpdatePluginInfoInstalled(std::vectorUpdateApplicationInfoInstalled(*applicationInfo_); AppLibPathMap appLibPaths {}; GetPluginNativeLibPath(pluginBundleInfos, appLibPaths); - AbilityRuntime::JsRuntime::SetAppLibPath(appLibPaths, applicationInfo_->isSystemApp); + AbilityRuntime::JsRuntime::SetOrUpdateLibPath(appLibPaths, applicationInfo_->isSystemApp); + std::vector moduleNames; + for (const auto &appLibPath : appLibPaths) { + moduleNames.emplace_back(appLibPath.first); + } if (IsPluginNamespaceInherited()) { - AbilityRuntime::JsRuntime::InheritPluginNamespace(pluginModuleNames); + AbilityRuntime::JsRuntime::InheritPluginNamespace(moduleNames); } } diff --git a/frameworks/native/runtime/js_runtime.cpp b/frameworks/native/runtime/js_runtime.cpp index 740683643d..6545eb999c 100644 --- a/frameworks/native/runtime/js_runtime.cpp +++ b/frameworks/native/runtime/js_runtime.cpp @@ -919,6 +919,31 @@ void JsRuntime::SetAppLibPath(const AppLibPathMap& appLibPaths, const bool& isSy } } +void JsRuntime::SetOrUpdateLibPath(const AppLibPathMap& appLibPaths, const bool& isSystemApp) +{ + TAG_LOGD(AAFwkTag::JSRUNTIME, "SetOrUpdate library path"); + + if (appLibPaths.size() == 0) { + TAG_LOGW(AAFwkTag::JSRUNTIME, "no lib path to set"); + return; + } + + auto moduleManager = NativeModuleManager::GetInstance(); + if (moduleManager == nullptr) { + TAG_LOGE(AAFwkTag::JSRUNTIME, "null moduleManager"); + return; + } + + for (const auto &appLibPath : appLibPaths) { + std::string pluginNamespace; + if (moduleManager->GetLdNamespaceName(appLibPath.first, pluginNamespace)) { + moduleManager->UpdateNamespaceLibPath(appLibPath.first, appLibPath.second); + } else { + moduleManager->SetAppLibPath(appLibPath.first, appLibPath.second, isSystemApp); + } + } +} + void JsRuntime::InheritPluginNamespace(const std::vector &moduleNames) { auto moduleManager = NativeModuleManager::GetInstance(); diff --git a/interfaces/inner_api/runtime/include/js_runtime.h b/interfaces/inner_api/runtime/include/js_runtime.h index d410603824..f7c3366cf4 100644 --- a/interfaces/inner_api/runtime/include/js_runtime.h +++ b/interfaces/inner_api/runtime/include/js_runtime.h @@ -75,6 +75,7 @@ public: static std::unique_ptr Create(const Options& options); static void SetAppLibPath(const AppLibPathMap& appLibPaths, const bool& isSystemApp = false); + static void SetOrUpdateLibPath(const AppLibPathMap& appLibPaths, const bool& isSystemApp = false); static void InheritPluginNamespace(const std::vector &moduleNames); static void CreatePluginDefaultNamespace(const std::string &lddictorys); diff --git a/test/unittest/runtime_test/js_runtime_test.cpp b/test/unittest/runtime_test/js_runtime_test.cpp index a319adda2e..1bb983a6ab 100755 --- a/test/unittest/runtime_test/js_runtime_test.cpp +++ b/test/unittest/runtime_test/js_runtime_test.cpp @@ -1956,5 +1956,26 @@ HWTEST_F(JsRuntimeTest, RegisterUncatchableExceptionHandler_0100, TestSize.Level EXPECT_NE(jsRuntime, nullptr); TAG_LOGI(AAFwkTag::TEST, "RegisterUncatchableExceptionHandler_0100 end"); } + +/** + * @tc.name: JsRuntimeTestSetOrUpdateLibPath_0100 + * @tc.desc: JsRuntime Test for SetOrUpdateLibPath + * @tc.type: FUNC + * @tc.require: issueI581RO + */ +HWTEST_F(JsRuntimeTest, JsRuntimeTestSetOrUpdateLibPath_0100, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "SetOrUpdateLibPath_0100 start"); + std::string appLibPathKey = TEST_BUNDLE_NAME + TEST_MODULE_NAME; + std::string libPath = TEST_LIB_PATH; + + AppLibPathMap appLibPaths {}; + JsRuntime::SetOrUpdateLibPath(appLibPaths); + + appLibPaths[appLibPathKey].emplace_back(libPath); + JsRuntime::SetOrUpdateLibPath(appLibPaths); + EXPECT_NE(appLibPaths.size(), 0); + TAG_LOGI(AAFwkTag::TEST, "SetOrUpdateLibPath_0100 end"); +} } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file