mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-25 12:23:20 -04:00
childProcessManager代码检视修改
Signed-off-by: zhangyuhang72 <zhangyuhang72@huawei.com> Change-Id: Ied98b893c0db0e807537d1380c4def5610d0816e
This commit is contained in:
@@ -32,9 +32,10 @@ std::shared_ptr<ChildProcess> ChildProcess::Create(const std::unique_ptr<Runtime
|
||||
}
|
||||
}
|
||||
|
||||
void ChildProcess::Init(const std::shared_ptr<ChildProcessStartInfo> &info)
|
||||
bool ChildProcess::Init(const std::shared_ptr<ChildProcessStartInfo> &info)
|
||||
{
|
||||
processStartInfo_ = info;
|
||||
return true;
|
||||
}
|
||||
|
||||
void ChildProcess::OnStart() {}
|
||||
|
||||
@@ -81,6 +81,10 @@ ChildProcessManagerErrorCode ChildProcessManager::StartChildProcessBySelfFork(co
|
||||
}
|
||||
std::shared_ptr<AbilityRuntime::ApplicationContext> applicationContext =
|
||||
AbilityRuntime::ApplicationContext::GetInstance();
|
||||
if (applicationContext == nullptr) {
|
||||
HILOG_ERROR("Get applicationContext failed.");
|
||||
return ChildProcessManagerErrorCode::ERR_GET_APPLICATION_CONTEXT_FAILED;
|
||||
}
|
||||
std::string bundleName = applicationContext->GetBundleName();
|
||||
AppExecFwk::HapModuleInfo hapModuleInfo;
|
||||
if (!GetHapModuleInfo(bundleName, hapModuleInfo)) {
|
||||
@@ -129,6 +133,10 @@ bool ChildProcessManager::IsChildProcess()
|
||||
void ChildProcessManager::HandleChildProcess(const std::string &srcEntry, AppExecFwk::HapModuleInfo &hapModuleInfo)
|
||||
{
|
||||
std::shared_ptr<AppExecFwk::EventRunner> eventRunner = AppExecFwk::EventRunner::GetMainEventRunner();
|
||||
if (eventRunner == nullptr) {
|
||||
HILOG_ERROR("Get main eventRunner failed.");
|
||||
return;
|
||||
}
|
||||
eventRunner->Stop();
|
||||
|
||||
auto runtime = CreateRuntime(hapModuleInfo);
|
||||
@@ -146,14 +154,26 @@ void ChildProcessManager::HandleChildProcess(const std::string &srcEntry, AppExe
|
||||
processStartInfo->isEsModule = (hapModuleInfo.compileMode == AppExecFwk::CompileMode::ES_MODULE);
|
||||
|
||||
auto process = ChildProcess::Create(runtime);
|
||||
process->Init(processStartInfo);
|
||||
if (process == nullptr) {
|
||||
HILOG_ERROR("Failed to create ChildProcess.");
|
||||
return;
|
||||
}
|
||||
bool ret = process->Init(processStartInfo);
|
||||
if (!ret) {
|
||||
HILOG_ERROR("JsChildProcess init failed.");
|
||||
return;
|
||||
}
|
||||
process->OnStart();
|
||||
}
|
||||
|
||||
bool ChildProcessManager::GetHapModuleInfo(const std::string &bundleName, AppExecFwk::HapModuleInfo &hapModuleInfo)
|
||||
{
|
||||
auto bundleObj =
|
||||
DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
|
||||
auto sysMrgClient = DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance();
|
||||
if (sysMrgClient == nullptr) {
|
||||
HILOG_ERROR("Failed to get SysMrgClient.");
|
||||
return false;
|
||||
}
|
||||
auto bundleObj = sysMrgClient->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
|
||||
if (bundleObj == nullptr) {
|
||||
HILOG_ERROR("Failed to get bundle manager service.");
|
||||
return false;
|
||||
@@ -198,6 +218,10 @@ std::unique_ptr<AbilityRuntime::Runtime> ChildProcessManager::CreateRuntime(AppE
|
||||
{
|
||||
std::shared_ptr<AbilityRuntime::ApplicationContext> applicationContext =
|
||||
AbilityRuntime::ApplicationContext::GetInstance();
|
||||
if (applicationContext == nullptr) {
|
||||
HILOG_ERROR("Get applicationContext failed.");
|
||||
return nullptr;
|
||||
}
|
||||
std::shared_ptr<AppExecFwk::ApplicationInfo> applicationInfo = applicationContext->GetApplicationInfo();
|
||||
if (applicationInfo == nullptr) {
|
||||
HILOG_ERROR("applicationInfo is nullptr");
|
||||
|
||||
@@ -31,15 +31,24 @@ JsChildProcess::JsChildProcess(JsRuntime &jsRuntime) : jsRuntime_(jsRuntime) {}
|
||||
JsChildProcess::~JsChildProcess()
|
||||
{
|
||||
HILOG_DEBUG("JsChildProcess destructor.");
|
||||
jsRuntime_.FreeNativeReference(std::move(jsChildProcessObj_));
|
||||
}
|
||||
|
||||
void JsChildProcess::Init(const std::shared_ptr<ChildProcessStartInfo> &info)
|
||||
bool JsChildProcess::Init(const std::shared_ptr<ChildProcessStartInfo> &info)
|
||||
{
|
||||
HILOG_INFO("JsChildProcess Init called");
|
||||
ChildProcess::Init(info);
|
||||
if (info == nullptr) {
|
||||
HILOG_ERROR("info is nullptr.");
|
||||
return false;
|
||||
}
|
||||
bool ret = ChildProcess::Init(info);
|
||||
if (!ret) {
|
||||
HILOG_ERROR("ChildProcess init failed.");
|
||||
return false;
|
||||
}
|
||||
if (info->srcEntry.empty()) {
|
||||
HILOG_ERROR("ChildProcessStartInfo srcEntry is empty");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
std::string srcPath;
|
||||
srcPath.append(info->moduleName).append("/");
|
||||
@@ -55,8 +64,9 @@ void JsChildProcess::Init(const std::shared_ptr<ChildProcessStartInfo> &info)
|
||||
jsChildProcessObj_ = jsRuntime_.LoadModule(moduleName, srcPath, info->hapPath, info->isEsModule);
|
||||
if (jsChildProcessObj_ == nullptr) {
|
||||
HILOG_ERROR("Failed to get ChildProcess object");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void JsChildProcess::OnStart()
|
||||
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
|
||||
static std::shared_ptr<ChildProcess> Create(const std::unique_ptr<Runtime> &runtime);
|
||||
|
||||
virtual void Init(const std::shared_ptr<ChildProcessStartInfo> &info);
|
||||
virtual bool Init(const std::shared_ptr<ChildProcessStartInfo> &info);
|
||||
virtual void OnStart();
|
||||
|
||||
protected:
|
||||
|
||||
@@ -28,6 +28,7 @@ enum class ChildProcessManagerErrorCode {
|
||||
ERR_ALREADY_IN_CHILD_PROCESS = 2,
|
||||
ERR_GET_HAP_INFO_FAILED = 3,
|
||||
ERR_FORK_FAILED = 4,
|
||||
ERR_GET_APPLICATION_CONTEXT_FAILED = 5,
|
||||
};
|
||||
|
||||
const std::map<ChildProcessManagerErrorCode, AbilityErrorCode> INTERNAL_ERR_CODE_MAP = {
|
||||
@@ -38,6 +39,7 @@ const std::map<ChildProcessManagerErrorCode, AbilityErrorCode> INTERNAL_ERR_CODE
|
||||
AbilityErrorCode::ERROR_CODE_OPERATION_NOT_SUPPORTED },
|
||||
{ ChildProcessManagerErrorCode::ERR_GET_HAP_INFO_FAILED, AbilityErrorCode::ERROR_CODE_INNER },
|
||||
{ ChildProcessManagerErrorCode::ERR_FORK_FAILED, AbilityErrorCode::ERROR_CODE_INNER },
|
||||
{ ChildProcessManagerErrorCode::ERR_GET_APPLICATION_CONTEXT_FAILED, AbilityErrorCode::ERROR_CODE_INNER },
|
||||
};
|
||||
|
||||
class ChildProcessManagerErrorUtil {
|
||||
|
||||
@@ -29,8 +29,8 @@ public:
|
||||
|
||||
static std::shared_ptr<ChildProcess> Create(const std::unique_ptr<Runtime> &runtime);
|
||||
|
||||
virtual void Init(const std::shared_ptr<ChildProcessStartInfo> &info) override;
|
||||
virtual void OnStart() override;
|
||||
bool Init(const std::shared_ptr<ChildProcessStartInfo> &info) override;
|
||||
void OnStart() override;
|
||||
|
||||
private:
|
||||
napi_value CallObjectMethod(const char *name, napi_value const *argv = nullptr, size_t argc = 0);
|
||||
|
||||
Reference in New Issue
Block a user