add SetOrUpdateLibPath

Signed-off-by: 任国军 <renguojun1@h-partners.com>
This commit is contained in:
任国军
2026-03-17 16:36:34 +08:00
parent c4babab5f7
commit c85309fbba
4 changed files with 53 additions and 2 deletions
+6 -2
View File
@@ -2397,9 +2397,13 @@ void MainThread::DoUpdatePluginInfoInstalled(std::vector<AppExecFwk::PluginBundl
application_->UpdateApplicationInfoInstalled(*applicationInfo_);
AppLibPathMap appLibPaths {};
GetPluginNativeLibPath(pluginBundleInfos, appLibPaths);
AbilityRuntime::JsRuntime::SetAppLibPath(appLibPaths, applicationInfo_->isSystemApp);
AbilityRuntime::JsRuntime::SetOrUpdateLibPath(appLibPaths, applicationInfo_->isSystemApp);
std::vector<std::string> moduleNames;
for (const auto &appLibPath : appLibPaths) {
moduleNames.emplace_back(appLibPath.first);
}
if (IsPluginNamespaceInherited()) {
AbilityRuntime::JsRuntime::InheritPluginNamespace(pluginModuleNames);
AbilityRuntime::JsRuntime::InheritPluginNamespace(moduleNames);
}
}
+25
View File
@@ -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<std::string> &moduleNames)
{
auto moduleManager = NativeModuleManager::GetInstance();
@@ -75,6 +75,7 @@ public:
static std::unique_ptr<JsRuntime> 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<std::string> &moduleNames);
static void CreatePluginDefaultNamespace(const std::string &lddictorys);
@@ -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