diff --git a/appspawn.gni b/appspawn.gni index cdc3fa6221e99175a10e1b48b7bb60399871282b..2f0fe1f03f3a2aec362682644c947e189b9cb608 100644 --- a/appspawn.gni +++ b/appspawn.gni @@ -40,6 +40,7 @@ declare_args() { appspawn_support_local_debugger = false appspawn_hitrace_option = true appspawn_napi_preload_path = "../appspawn_preload.json" + appspawn_arkweb_preload = true } if (!defined(global_parts_info) || diff --git a/bundle.json b/bundle.json index 7b73228e1092dfbfdf64c7765a12639c85050992..6582a611239c0ac2be5f8a36beef5e42305da719 100644 --- a/bundle.json +++ b/bundle.json @@ -31,7 +31,8 @@ "appspawn_custom_sandbox", "appspawn_support_nosharefs", "appspawn_support_local_debugger", - "appspawn_napi_preload_path" + "appspawn_napi_preload_path", + "appspawn_arkweb_preload" ], "rom": "296KB", "ram": "13125KB", diff --git a/modules/nweb_adapter/BUILD.gn b/modules/nweb_adapter/BUILD.gn index acd15abe223a366520e29f0fe8fac4c159b09e25..1b73d080ccb7c0ac22c79aa51bed66e11db854a9 100644 --- a/modules/nweb_adapter/BUILD.gn +++ b/modules/nweb_adapter/BUILD.gn @@ -31,6 +31,9 @@ ohos_shared_library("appspawn_nweb") { if (target_cpu == "x86_64") { defines += [ "webview_x86_64" ] } + if (appspawn_arkweb_preload) { + defines += [ "arkweb_preload" ] + } external_deps = [ "c_utils:utils", diff --git a/modules/nweb_adapter/nwebspawn_adapter.cpp b/modules/nweb_adapter/nwebspawn_adapter.cpp index c8562fa1920d09959f9162f37bf4946b97ab75c1..a0e16f7d377a0f5355669209cb2c4dbf3441f05d 100644 --- a/modules/nweb_adapter/nwebspawn_adapter.cpp +++ b/modules/nweb_adapter/nwebspawn_adapter.cpp @@ -36,10 +36,10 @@ #endif namespace { -#if defined(webview_arm64) +#ifdef webview_arm64 const std::string ARK_WEB_CORE_HAP_LIB_PATH = "/data/storage/el1/bundle/arkwebcore/libs/arm64"; -#elif defined(webview_x86_64) +#elif webview_x86_64 const std::string ARK_WEB_CORE_HAP_LIB_PATH = "/data/storage/el1/bundle/arkwebcore/libs/x86_64"; #else @@ -55,6 +55,12 @@ namespace { const std::string OHOS_ADPT_GLUE_SRC_LIB_PATH = "/system/lib64/libohos_adapter_glue_source.z.so"; +#ifdef arkweb_preload + const std::string ARKWEB_BUNDLE_NAME = "com.ohos.arkwebcore"; +#else + const std::string ARKWEB_BUNDLE_NAME = "com.huawei.hmos.arkwebcore"; +#endif + typedef enum { PRELOAD_NO = 0, // 不预加载 PRELOAD_PARTIAL = 1, // 只预加载libohos_adapter_glue_source.z.so @@ -160,12 +166,40 @@ APPSPAWN_STATIC int RunChildProcessor(AppSpawnContent *content, AppSpawnClient * return 0; } +static std::string GetOhosAdptGlueSrcLibPath() +{ +#ifdef webview_arm64 + const std::string ARK_WEB_CORE_HAP_LIB_PATH = + "/system/lib64/libohos_adapter_glue_source.z.so"; +#else + const std::string ARK_WEB_CORE_HAP_LIB_PATH = + "/system/lib/libohos_adapter_glue_source.z.so"; +#endif + return ARK_WEB_CORE_HAP_LIB_PATH; +} + +static std::string GetArkWebEngineLibPath() +{ +#ifdef webview_arm64 + const std::string ARK_WEB_CORE_HAP_LIB_PATH = + "/data/app/el1/bundle/public/" + ARKWEB_BUNDLE_NAME + "/libs/arm64"; +#elif webview_x86_64 + const std::string ARK_WEB_CORE_HAP_LIB_PATH = + "/data/app/el1/bundle/public/" + ARKWEB_BUNDLE_NAME + "/libs/x86_64"; +#else + const std::string ARK_WEB_CORE_HAP_LIB_PATH = + "/data/app/el1/bundle/public/" + ARKWEB_BUNDLE_NAME + "/libs/arm"; +#endif + return ARK_WEB_CORE_HAP_LIB_PATH; +} + static void PreLoadArkWebEngineLib() { Dl_namespace dlns; Dl_namespace ndkns; dlns_init(&dlns, "nweb_ns"); - dlns_create(&dlns, ARK_WEB_ENGINE_LIB_PRELOAD_PATH.c_str()); + const std::string arkWebEngineLibPath = GetArkWebEngineLibPath(); + dlns_create(&dlns, arkWebEngineLibPath.c_str()); dlns_get("ndk", &ndkns); dlns_inherit(&dlns, &ndkns, "allow_all_shared_libs"); void *webEngineHandle = dlopen_ns(&dlns, ARK_WEB_ENGINE_LIB_NAME.c_str(), RTLD_NOW | RTLD_GLOBAL); @@ -176,12 +210,14 @@ static void PreLoadArkWebEngineLib() static void PreLoadOHOSAdptGlueSrcLib() { - void *ohosAdptGlueSrcHandle = dlopen(OHOS_ADPT_GLUE_SRC_LIB_PATH.c_str(), RTLD_NOW | RTLD_GLOBAL); + const std::string ohosAdptGlueSrcLibPath = GetOhosAdptGlueSrcLibPath(); + void *ohosAdptGlueSrcHandle = dlopen(ohosAdptGlueSrcLibPath.c_str(), RTLD_NOW | RTLD_GLOBAL); if (!ohosAdptGlueSrcHandle) { APPSPAWN_LOGE("Fail to dlopen libohos_adapter_glue_source.z.so, errno: %{public}d", errno); } } +#ifndef arkweb_preload static int GetSysParamPreLoadMode() { const int BUFFER_LEN = 8; @@ -190,6 +226,7 @@ static int GetSysParamPreLoadMode() int ret = std::atoi(preLoadMode); return ret; } +#endif static int PreLoadNwebSpawn(AppSpawnMgr *content) { @@ -201,7 +238,11 @@ static int PreLoadNwebSpawn(AppSpawnMgr *content) RegChildLooper(&content->content, RunChildProcessor); // preload render lib +#ifdef arkweb_preload + int preloadMode = RenderPreLoadMode::PRELOAD_FULL; +#else int preloadMode = GetSysParamPreLoadMode(); +#endif APPSPAWN_LOGI("NwebSpawn preload render lib mode: %{public}d", preloadMode); if (preloadMode == PRELOAD_PARTIAL) { PreLoadOHOSAdptGlueSrcLib(); diff --git a/nwebspawn.cfg b/nwebspawn.cfg index f29e3c899b67e8ca195e09f52382d62b02503c44..e6cc4dfbdfe4a7837fe8a224a01fdb55ee0b859c 100644 --- a/nwebspawn.cfg +++ b/nwebspawn.cfg @@ -1,4 +1,11 @@ { + "jobs" : [{ + "name" : "param:nwebspawnservicestart", + "condition" : "bootevent.boot.completed=true", + "cmds" : [ + "start nwebspawn" + ] + }], "services" : [{ "name" : "nwebspawn", "path" : ["/system/bin/nwebspawn", @@ -21,6 +28,7 @@ "option" : [ ] }], + "start-mode" : "condition", "sandbox" : 0, "secon" : "u:r:nwebspawn:s0" }