Merge branch 'master' of gitee.com:openharmony/startup_appspawn into 770

This commit is contained in:
chen 2022-07-25 14:16:01 +00:00 committed by Gitee
commit 4fb1305c43
5 changed files with 43 additions and 6 deletions

View File

@ -52,9 +52,12 @@ ohos_executable("appspawn") {
external_deps = [
"ability_base:want",
"ability_runtime:app_manager",
"ability_runtime:runtime",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
"napi:ace_napi",
"utils_base:utils",
]

View File

@ -15,6 +15,10 @@
#include "appspawn_adapter.h"
#include "js_runtime.h"
#include "parameters.h"
#include "runtime.h"
#include "foundation/ability/ability_runtime/interfaces/kits/native/appkit/app/main_thread.h"
void LoadExtendLib(AppSpawnContent *content)
@ -24,14 +28,43 @@ void LoadExtendLib(AppSpawnContent *content)
#else
const char *acelibdir("/system/lib/libace.z.so");
#endif
APPSPAWN_LOGI("MainThread::LoadAbilityLibrary. Start calling dlopen acelibdir.");
APPSPAWN_LOGI("LoadExtendLib: Start calling dlopen acelibdir.");
#ifndef APPSPAWN_TEST
void *aceAbilityLib = NULL;
aceAbilityLib = dlopen(acelibdir, RTLD_NOW | RTLD_GLOBAL);
APPSPAWN_CHECK(aceAbilityLib != NULL, return, "Fail to dlopen %s, [%s]", acelibdir, dlerror());
#endif
APPSPAWN_LOGI("Success to dlopen %s", acelibdir);
APPSPAWN_LOGI("MainThread::LoadAbilityLibrary. End calling dlopen");
APPSPAWN_LOGI("LoadExtendLib: Success to dlopen %s", acelibdir);
APPSPAWN_LOGI("LoadExtendLib: End calling dlopen");
bool preload = OHOS::system::GetBoolParameter("const.appspawn.preload", false);
if (!preload) {
APPSPAWN_LOGI("LoadExtendLib: Do not preload JS VM");
return;
}
APPSPAWN_LOGI("LoadExtendLib: Start preload JS VM");
OHOS::AbilityRuntime::Runtime::Options options;
options.lang = OHOS::AbilityRuntime::Runtime::Language::JS;
options.loadAce = true;
options.preload = true;
auto runtime = OHOS::AbilityRuntime::Runtime::Create(options);
if (!runtime) {
APPSPAWN_LOGE("LoadExtendLib: Failed to create runtime");
return;
}
// Preload napi module
runtime->PreloadSystemModule("application.Ability");
runtime->PreloadSystemModule("application.Context");
runtime->PreloadSystemModule("application.AbilityContext");
// Save preloaded runtime
OHOS::AbilityRuntime::Runtime::SavePreloaded(std::move(runtime));
APPSPAWN_LOGI("LoadExtendLib: End preload JS VM");
}
void RunChildProcessor(AppSpawnContent *content, AppSpawnClient *client)

View File

@ -61,7 +61,7 @@ executable("appspawn") {
"//base/startup/init/interfaces/innerkits:libbegetutil",
"//build/lite/config/component/cJSON:cjson_shared",
"//foundation/communication/ipc/interfaces/innerkits/c/ipc:ipc_single",
"//foundation/distributeddatamgr/appdatamgr/kv_store/interfaces/inner_api/kv_store:kv_store",
"//foundation/distributeddatamgr/kv_store/interfaces/inner_api/kv_store:kv_store",
"//foundation/systemabilitymgr/samgr_lite/samgr:samgr",
"//third_party/bounds_checking_function:libsec_shared",
]

View File

@ -89,13 +89,14 @@ ohos_unittest("AppSpawn_ut") {
external_deps = [
"ability_base:want",
"ability_runtime:app_manager",
"ability_runtime:runtime",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"hiviewdfx_hilog_native:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
"napi:ace_napi",
"utils_base:utils",
]
}

View File

@ -52,7 +52,7 @@ unittest("AppSpawnLiteTest") {
"//base/startup/init/interfaces/innerkits:libbegetutil",
"//build/lite/config/component/cJSON:cjson_shared",
"//foundation/communication/ipc/interfaces/innerkits/c/ipc:ipc_single",
"//foundation/distributeddatamgr/appdatamgr/kv_store/interfaces/inner_api/kv_store:kv_store",
"//foundation/distributeddatamgr/kv_store/interfaces/inner_api/kv_store:kv_store",
"//foundation/systemabilitymgr/samgr_lite/samgr:samgr",
"//third_party/bounds_checking_function:libsec_shared",
]