From e9880dec17a78cf4d9a0e7d945e1b7870d5bd29d Mon Sep 17 00:00:00 2001 From: zhangyuhang72 Date: Wed, 18 Jun 2025 18:02:57 +0800 Subject: [PATCH] =?UTF-8?q?childProcessManager=E9=94=99=E8=AF=AF=E7=A0=81?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangyuhang72 Change-Id: Id68d063c354a9c3e2945ccff7e05408742539b46 --- .../child_process_manager.cpp | 10 +++++- .../include/child_process_manager.h | 1 + .../child_process_manager_test.cpp | 34 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/frameworks/native/ability/native/child_process_manager/child_process_manager.cpp b/frameworks/native/ability/native/child_process_manager/child_process_manager.cpp index bb898de0a5a..aee877affe8 100644 --- a/frameworks/native/ability/native/child_process_manager/child_process_manager.cpp +++ b/frameworks/native/ability/native/child_process_manager/child_process_manager.cpp @@ -157,11 +157,19 @@ ChildProcessManagerErrorCode ChildProcessManager::StartChildProcessWithArgs( TAG_LOGD(AAFwkTag::PROCESSMGR, "AppMgr StartChildProcess ret:%{public}d", ret); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::PROCESSMGR, "StartChildProcess error:%{public}d", ret); - return ChildProcessManagerErrorUtil::GetChildProcessManagerErrorCode(ret); + return GetErrorCodeCompat(ret, childProcessType); } return ChildProcessManagerErrorCode::ERR_OK; } +ChildProcessManagerErrorCode ChildProcessManager::GetErrorCodeCompat(int32_t ret, int32_t childProcessType) +{ + if (ret == AAFwk::ERR_NOT_SUPPORT_CHILD_PROCESS && childProcessType == AppExecFwk::CHILD_PROCESS_TYPE_JS) { + return ChildProcessManagerErrorCode::ERR_MULTI_PROCESS_MODEL_DISABLED; + } + return ChildProcessManagerErrorUtil::GetChildProcessManagerErrorCode(ret); +} + ChildProcessManagerErrorCode ChildProcessManager::StartNativeChildProcessByAppSpawnFork( const std::string &libName, const sptr &callbackStub, const std::string &customProcessName) { diff --git a/interfaces/inner_api/child_process_manager/include/child_process_manager.h b/interfaces/inner_api/child_process_manager/include/child_process_manager.h index e9b5404d428..83392272fd8 100644 --- a/interfaces/inner_api/child_process_manager/include/child_process_manager.h +++ b/interfaces/inner_api/child_process_manager/include/child_process_manager.h @@ -79,6 +79,7 @@ private: sptr GetAppMgr(); void MakeProcessName(const std::string &srcEntry); bool IsMultiProcessFeatureApp(const AppExecFwk::BundleInfo &bundleInfo); + ChildProcessManagerErrorCode GetErrorCodeCompat(int32_t ret, int32_t childProcessType); static bool signalRegistered_; bool isChildProcessBySelfFork_ = false; diff --git a/test/unittest/child_process_manager_test/child_process_manager_test.cpp b/test/unittest/child_process_manager_test/child_process_manager_test.cpp index bf991d9e4dc..5074571ef43 100644 --- a/test/unittest/child_process_manager_test/child_process_manager_test.cpp +++ b/test/unittest/child_process_manager_test/child_process_manager_test.cpp @@ -529,5 +529,39 @@ HWTEST_F(ChildProcessManagerTest, IsMultiProcessFeatureApp_0400, TestSize.Level2 bool ret = ChildProcessManager::GetInstance().IsMultiProcessFeatureApp(bundleInfo); EXPECT_TRUE(ret); } + +/** + * @tc.number: GetErrorCodeCompat + * @tc.desc: Test GetErrorCodeCompat works. + * @tc.type: FUNC + */ +HWTEST_F(ChildProcessManagerTest, GetErrorCodeCompat_0100, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "GetErrorCodeCompat_0100 start."); + + auto &childProcessManager = ChildProcessManager::GetInstance(); + + auto ret = AAFwk::ERR_NOT_SUPPORT_CHILD_PROCESS; + auto childProcessType = AppExecFwk::CHILD_PROCESS_TYPE_JS; + auto errCode = childProcessManager.GetErrorCodeCompat(ret, childProcessType); + EXPECT_EQ(errCode, ChildProcessManagerErrorCode::ERR_MULTI_PROCESS_MODEL_DISABLED); + + ret = AAFwk::ERR_NOT_SUPPORT_CHILD_PROCESS; + childProcessType = AppExecFwk::CHILD_PROCESS_TYPE_ARK; + errCode = childProcessManager.GetErrorCodeCompat(ret, childProcessType); + EXPECT_NE(errCode, ChildProcessManagerErrorCode::ERR_MULTI_PROCESS_MODEL_DISABLED); + + ret = AAFwk::INNER_ERR; + childProcessType = AppExecFwk::CHILD_PROCESS_TYPE_JS; + errCode = childProcessManager.GetErrorCodeCompat(ret, childProcessType); + EXPECT_NE(errCode, ChildProcessManagerErrorCode::ERR_MULTI_PROCESS_MODEL_DISABLED); + + ret = AAFwk::INNER_ERR; + childProcessType = AppExecFwk::CHILD_PROCESS_TYPE_ARK; + errCode = childProcessManager.GetErrorCodeCompat(ret, childProcessType); + EXPECT_NE(errCode, ChildProcessManagerErrorCode::ERR_MULTI_PROCESS_MODEL_DISABLED); + + TAG_LOGI(AAFwkTag::TEST, "GetErrorCodeCompat_0100 end."); +} } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file -- Gitee