diff --git a/BUILD.gn b/BUILD.gn index 433afa933eae399df772364cb7820ea9998a0e63..71b4bf2773456f0e1daf942bc343ec8d39ecd6ce 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -142,9 +142,6 @@ ohos_static_library("nwebspawn_server") { ohos_executable("nwebspawn") { defines = [ "NWEB_SPAWN" ] - if (target_cpu == "arm64") { - defines += [ "webview_arm64" ] - } sources = [ "${appspawn_path}/adapter/appspawn_nweb.cpp", "${appspawn_path}/standard/main.c", @@ -153,7 +150,15 @@ ohos_executable("nwebspawn") { ] configs = [ ":appspawn_config" ] deps = [ "${appspawn_path}:nwebspawn_server" ] - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + external_deps = [ + "ability_base:want", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "os_account:os_account_innerkits", + "samgr_standard:samgr_proxy", + ] install_enable = true subsystem_name = "${subsystem_name}" diff --git a/adapter/appspawn_nweb.cpp b/adapter/appspawn_nweb.cpp index 990873fe55060c3aba3b09a994701d0f35662acb..cf85978191e15c82cf3b875dc89b491b8f1bd789 100644 --- a/adapter/appspawn_nweb.cpp +++ b/adapter/appspawn_nweb.cpp @@ -19,6 +19,13 @@ #include #include #include +#include "application_info.h" +#include "bundle_mgr_interface.h" +#include "bundle_mgr_proxy.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "os_account_manager.h" +#include "system_ability_definition.h" #include "appspawn_service.h" #include "appspawn_adapter.h" @@ -32,16 +39,59 @@ namespace { constexpr int32_t RENDER_PROCESS_MAX_NUM = 16; std::map g_renderProcessMap; void *g_nwebHandle = nullptr; + std::string LOAD_LIB_DIR; } -void LoadExtendLib(AppSpawnContent *content) +OHOS::sptr GetBundleMgr() { -#ifdef webview_arm64 - const std::string LOAD_LIB_DIR = "/data/app/el1/bundle/public/com.ohos.nweb/libs/arm64"; -#else - const std::string LOAD_LIB_DIR = "/data/app/el1/bundle/public/com.ohos.nweb/libs/arm"; -#endif + auto samgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + APPSPAWN_LOGE("GetBundleMgr GetSystemAbilityManager is null"); + return nullptr; + } + auto bundleMgrSa = samgr->GetSystemAbility(OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + if (bundleMgrSa == nullptr) { + APPSPAWN_LOGE("GetBundleMgr GetSystemAbility is null"); + return nullptr; + } + return OHOS::iface_cast(bundleMgrSa); +} +bool GetNativeLibraryPath(void) +{ + const std::string NWEB_BUNDLE_NAME = "com.ohos.nweb"; + std::vector userIds; + if (OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(userIds) != OHOS::ERR_OK) { + APPSPAWN_LOGE("QueryActiveOsAccountIds failed!"); + return false; + } + if (userIds.empty()) { + APPSPAWN_LOGE("QueryActiveOsAccountIds userIds empty"); + return false; + } + auto reqUserId = userIds[0]; + auto iBundleMgr = GetBundleMgr(); + if (!iBundleMgr) { + APPSPAWN_LOGE("can not get iBundleMgr"); + return false; + } + OHOS::AppExecFwk::ApplicationInfo appInfo; + bool result = iBundleMgr-> + GetApplicationInfo(NWEB_BUNDLE_NAME, OHOS::AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, reqUserId, appInfo); + if (!result) { + APPSPAWN_LOGE("GetApplicationInfo failed"); + return false; + } + LOAD_LIB_DIR = appInfo.codePath + "/" + appInfo.nativeLibraryPath; + return true; +} + +void LoadExtendLib(AppSpawnContent *content) +{ + if (!GetNativeLibraryPath()) { + APPSPAWN_LOGE("GetNativeLibraryPath failed"); + return; + } #ifdef __MUSL__ Dl_namespace dlns; dlns_init(&dlns, "nweb_ns");