From 5eba8d74e750c0b54c6ae397d292b26c9fc24baa Mon Sep 17 00:00:00 2001 From: renjianhao Date: Wed, 18 Mar 2026 14:14:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=A7=A3=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: manual Signed-off-by: renjh5496 --- .../src/ets_child_process_manager.cpp | 38 ++- .../@ohos.app.ability.childProcessManager.ets | 2 + .../js_child_process_manager.cpp | 30 +++ .../child_process_manager.cpp | 42 ++++ .../src/native_child_process.cpp | 7 + .../include/child_process_manager.h | 3 + .../child_process/native_child_process.h | 1 + services/appmgr/src/app_mgr_service_inner.cpp | 3 +- .../child_process_manager_test.cpp | 232 ++++++++++++++++++ 9 files changed, 355 insertions(+), 3 deletions(-) diff --git a/frameworks/ets/ani/child_process_manager/src/ets_child_process_manager.cpp b/frameworks/ets/ani/child_process_manager/src/ets_child_process_manager.cpp index 3145635717..ff22532cbd 100644 --- a/frameworks/ets/ani/child_process_manager/src/ets_child_process_manager.cpp +++ b/frameworks/ets/ani/child_process_manager/src/ets_child_process_manager.cpp @@ -108,6 +108,16 @@ public: GetInstance().OnStartNativeChildProcessCheck(env, etsSrcEntry, ChildProcessArgs, ChildProcessOptions); } + static bool IsArkChildProcessSupported(ani_env *env) + { + return GetInstance().OnIsArkChildProcessSupported(env); + } + + static bool IsNativeChildProcessSupported(ani_env *env) + { + return GetInstance().OnIsNativeChildProcessSupported(env); + } + private: void OnStartChildProcess(ani_env *env, ani_string etsSrcEntry, ani_enum_item etsStartMode, ani_object callback) { @@ -495,6 +505,26 @@ private: } return true; } + + bool OnIsArkChildProcessSupported(ani_env *env) + { + TAG_LOGD(AAFwkTag::PROCESSMGR, "IsArkChildProcessSupported called"); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::PROCESSMGR, "env is null"); + return false; + } + return AbilityRuntime::ChildProcessManager::GetInstance().IsArkChildProcessSupported(); + } + + bool OnIsNativeChildProcessSupported(ani_env *env) + { + TAG_LOGD(AAFwkTag::PROCESSMGR, "IsNativeChildProcessSupported called"); + if (env == nullptr) { + TAG_LOGE(AAFwkTag::PROCESSMGR, "env is null"); + return false; + } + return AbilityRuntime::ChildProcessManager::GetInstance().IsNativeChildProcessSupported(); + } }; void EtsChildProcessManagerInit(ani_env *env) @@ -547,7 +577,13 @@ void EtsChildProcessManagerInit(ani_env *env) ani_native_function {"nativeStartNativeChildProcessCheck", "C{std.core.String}C{@ohos.app.ability.ChildProcessArgs.ChildProcessArgs}" "C{@ohos.app.ability.ChildProcessOptions.ChildProcessOptions}:", - reinterpret_cast(EtsChildProcessManager::StartNativeChildProcessCheck)} + reinterpret_cast(EtsChildProcessManager::StartNativeChildProcessCheck)}, + ani_native_function {"isArkChildProcessSupported", + ":z", + reinterpret_cast(EtsChildProcessManager::IsArkChildProcessSupported)}, + ani_native_function {"isNativeChildProcessSupported", + ":z", + reinterpret_cast(EtsChildProcessManager::IsNativeChildProcessSupported)} }; status = env->Namespace_BindNativeFunctions(ns, kitFunctions.data(), kitFunctions.size()); if (status != ANI_OK) { diff --git a/frameworks/ets/ets/@ohos.app.ability.childProcessManager.ets b/frameworks/ets/ets/@ohos.app.ability.childProcessManager.ets index 2aac4dadac..b7589a94f3 100644 --- a/frameworks/ets/ets/@ohos.app.ability.childProcessManager.ets +++ b/frameworks/ets/ets/@ohos.app.ability.childProcessManager.ets @@ -31,6 +31,8 @@ namespace childProcessManager { export native function nativeStartArkChildProcess(srcEntry: string, args: ChildProcessArgs, options: ChildProcessOptions, callback: AsyncCallbackWrapper): void; export native function nativeStartNativeChildProcess(entryPoint: string, args: ChildProcessArgs, callback: AsyncCallbackWrapper): void; export native function nativeStartNativeChildProcess(entryPoint: string, args: ChildProcessArgs, options: ChildProcessOptions, callback: AsyncCallbackWrapper): void; + export native function isArkChildProcessSupported(): boolean; + export native function isNativeChildProcessSupported(): boolean; export native function nativeStartChildProcessCheck(srcEntry: string, startMode: StartMode): void; export native function nativeStartArkChildProcessCheck(srcEntry: string, args: ChildProcessArgs, options?: ChildProcessOptions): void; diff --git a/frameworks/js/napi/js_child_process_manager/js_child_process_manager.cpp b/frameworks/js/napi/js_child_process_manager/js_child_process_manager.cpp index 9bdb6e172f..161cc46a39 100644 --- a/frameworks/js/napi/js_child_process_manager/js_child_process_manager.cpp +++ b/frameworks/js/napi/js_child_process_manager/js_child_process_manager.cpp @@ -80,6 +80,16 @@ public: GET_CB_INFO_AND_CALL(env, info, JsChildProcessManager, OnStartNativeChildProcess); } + static napi_value IsArkChildProcessSupported(napi_env env, napi_callback_info info) + { + GET_CB_INFO_AND_CALL(env, info, JsChildProcessManager, OnIsArkChildProcessSupported); + } + + static napi_value IsNativeChildProcessSupported(napi_env env, napi_callback_info info) + { + GET_CB_INFO_AND_CALL(env, info, JsChildProcessManager, OnIsNativeChildProcessSupported); + } + private: napi_value OnStartChildProcess(napi_env env, size_t argc, napi_value* argv) { @@ -264,6 +274,22 @@ private: return result; } + napi_value OnIsArkChildProcessSupported(napi_env env, size_t argc, napi_value* argv) + { + TAG_LOGI(AAFwkTag::PROCESSMGR, "called"); + bool isSupported = ChildProcessManager::GetInstance().IsArkChildProcessSupported(); + TAG_LOGD(AAFwkTag::PROCESSMGR, "result:%{public}d", isSupported); + return CreateJsValue(env, isSupported); + } + + napi_value OnIsNativeChildProcessSupported(napi_env env, size_t argc, napi_value* argv) + { + TAG_LOGI(AAFwkTag::PROCESSMGR, "called"); + bool isSupported = ChildProcessManager::GetInstance().IsNativeChildProcessSupported(); + TAG_LOGD(AAFwkTag::PROCESSMGR, "result:%{public}d", isSupported); + return CreateJsValue(env, isSupported); + } + bool ParseArgsAndOptions(const napi_env &env, napi_value* argv, size_t argc, AppExecFwk::ChildProcessArgs &args, AppExecFwk::ChildProcessOptions &options) { @@ -338,6 +364,10 @@ napi_value JsChildProcessManagerInit(napi_env env, napi_value exportObj) BindNativeFunction(env, exportObj, "startArkChildProcess", moduleName, JsChildProcessManager::StartArkChildProcess); BindNativeFunction(env, exportObj, "startNativeChildProcess", moduleName, JsChildProcessManager::StartNativeChildProcess); + BindNativeFunction(env, exportObj, "isArkChildProcessSupported", moduleName, + JsChildProcessManager::IsArkChildProcessSupported); + BindNativeFunction(env, exportObj, "isNativeChildProcessSupported", moduleName, + JsChildProcessManager::IsNativeChildProcessSupported); return CreateJsUndefined(env); } } // namespace AbilityRuntime 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 4894a4e070..4b610080e8 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 @@ -628,5 +628,47 @@ ChildProcessManagerErrorCode ChildProcessManager::KillChildProcessByPid(int32_t } return ChildProcessManagerErrorCode::ERR_OK; } +bool ChildProcessManager::IsChildProcessSupportedImpl(bool isNative) +{ + TAG_LOGD(AAFwkTag::PROCESSMGR, "called"); + if (AAFwk::AppUtils::GetInstance().IsMultiProcessModel()) { + TAG_LOGD(AAFwkTag::PROCESSMGR, "MultiProcessModel enabled, support %{public}s child process", + isNative ? "native" : "ark"); + return true; + } + + AppExecFwk::BundleInfo bundleInfo; + bool hasBundleInfo = GetBundleInfo(bundleInfo); + if (!hasBundleInfo) { + TAG_LOGW(AAFwkTag::PROCESSMGR, "Failed to get bundle info"); + return false; + } + if (isNative) { + std::string appIdentifier = bundleInfo.signatureInfo.appIdentifier; + if (!appIdentifier.empty() && AAFwk::AppUtils::GetInstance().IsAllowNativeChildProcess(appIdentifier)) { + TAG_LOGD(AAFwkTag::PROCESSMGR, "App %{public}s in whitelist, support native child process", + bundleInfo.name.c_str()); + return true; + } + } + if (AAFwk::AppUtils::GetInstance().AllowChildProcessInMultiProcessFeatureApp()) { + if (IsMultiProcessFeatureApp(bundleInfo)) { + TAG_LOGD(AAFwkTag::PROCESSMGR, "MultiProcessFeatureApp with large_screen, support %{public}s child process", + isNative ? "native" : "ark"); + return true; + } + } + return false; +} + +bool ChildProcessManager::IsArkChildProcessSupported() +{ + return IsChildProcessSupportedImpl(false); +} + +bool ChildProcessManager::IsNativeChildProcessSupported() +{ + return IsChildProcessSupportedImpl(true); +} } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/child_process/src/native_child_process.cpp b/frameworks/native/child_process/src/native_child_process.cpp index 2a7d0ef9bb..ca746b06df 100644 --- a/frameworks/native/child_process/src/native_child_process.cpp +++ b/frameworks/native/child_process/src/native_child_process.cpp @@ -364,4 +364,11 @@ Ability_NativeChildProcess_ErrCode OH_Ability_KillChildProcess(int32_t pid) return ChildProcessManagerErrorUtil::CvtChildProcessManagerErrCode(cpmErr); } return NCP_NO_ERROR; +} + +bool OH_Ability_IsNativeChildProcessSupported() +{ + bool result = ChildProcessManager::GetInstance().IsNativeChildProcessSupported(); + TAG_LOGD(AAFwkTag::PROCESSMGR, "IsNativeChildProcessSupported: %{public}d", result); + return result; } \ No newline at end of file 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 7a86f61f9d..41289414a9 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 @@ -44,6 +44,8 @@ public: static void HandleSigChild(int32_t signo); bool IsChildProcess(); bool IsChildProcessBySelfFork(); + bool IsArkChildProcessSupported(); + bool IsNativeChildProcessSupported(); ChildProcessManagerErrorCode StartChildProcessBySelfFork(const std::string &srcEntry, pid_t &pid, bool isStaticChildProcess = false); ChildProcessManagerErrorCode StartChildProcessByAppSpawnFork(const std::string &srcEntry, pid_t &pid, @@ -91,6 +93,7 @@ private: sptr GetAppMgr(); void MakeProcessName(const std::string &srcEntry); bool IsMultiProcessFeatureApp(const AppExecFwk::BundleInfo &bundleInfo); + bool IsChildProcessSupportedImpl(bool isNative); ChildProcessManagerErrorCode GetErrorCodeCompat(int32_t ret, int32_t childProcessType); static bool signalRegistered_; diff --git a/interfaces/kits/c/ability/ability_runtime/child_process/native_child_process.h b/interfaces/kits/c/ability/ability_runtime/child_process/native_child_process.h index 1542ebbae8..3d48f92a29 100644 --- a/interfaces/kits/c/ability/ability_runtime/child_process/native_child_process.h +++ b/interfaces/kits/c/ability/ability_runtime/child_process/native_child_process.h @@ -504,6 +504,7 @@ Ability_NativeChildProcess_ErrCode OH_Ability_UnregisterNativeChildProcessExitCa */ Ability_NativeChildProcess_ErrCode OH_Ability_KillChildProcess(int32_t pid); +bool OH_Ability_IsNativeChildProcessSupported(); #ifdef __cplusplus } // extern "C" #endif diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 61a4f30c76..c97f4531bb 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -11653,8 +11653,7 @@ int32_t AppMgrServiceInner::CreateNativeChildProcess(const pid_t hostPid, const return ERR_INVALID_OPERATION; } - if (!AAFwk::AppUtils::GetInstance().IsSupportNativeChildProcess() && - !AllowNativeChildProcess(CHILD_PROCESS_TYPE_NATIVE, appRecord->GetAppIdentifier()) && + if (!AllowNativeChildProcess(CHILD_PROCESS_TYPE_NATIVE, appRecord->GetAppIdentifier()) && !AllowChildProcessInMultiProcessFeatureApp(appRecord)) { TAG_LOGE(AAFwkTag::APPMGR, "unSupport native child process"); return AAFwk::ERR_NOT_SUPPORT_NATIVE_CHILD_PROCESS; 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 3a931be37b..4e7cd3fc45 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 @@ -682,5 +682,237 @@ HWTEST_F(ChildProcessManagerTest, LoadFromAppRuntime_0300, TestSize.Level2) auto ret = ChildProcessManager::GetInstance().LoadFromAppRuntime("./ets/process/FeatureProcess.ts", hapModuleInfo); EXPECT_FALSE(ret); } + +/** + * @tc.number: IsArkChildProcessSupported_0100 + * @tc.desc: Test IsArkChildProcessSupported when MultiProcessModel is enabled + * @tc.type: FUNC + */ +HWTEST_F(ChildProcessManagerTest, IsArkChildProcessSupported_0100, TestSize.Level1) +{ + TAG_LOGD(AAFwkTag::TEST, "IsArkChildProcessSupported_0100 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + auto origIsLoaded = appUtils.isMultiProcessModel_.isLoaded; + auto origValue = appUtils.isMultiProcessModel_.value; + + appUtils.isMultiProcessModel_.isLoaded = true; + appUtils.isMultiProcessModel_.value = true; + + bool result = ChildProcessManager::GetInstance().IsArkChildProcessSupported(); + EXPECT_TRUE(result); + + appUtils.isMultiProcessModel_.isLoaded = origIsLoaded; + appUtils.isMultiProcessModel_.value = origValue; +} + +/** + * @tc.number: IsArkChildProcessSupported_0200 + * @tc.desc: Test IsArkChildProcessSupported when MultiProcessModel disabled and GetBundleInfo failed + * @tc.type: FUNC + */ +HWTEST_F(ChildProcessManagerTest, IsArkChildProcessSupported_0200, TestSize.Level1) +{ + TAG_LOGD(AAFwkTag::TEST, "IsArkChildProcessSupported_0200 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + auto origIsLoaded = appUtils.isMultiProcessModel_.isLoaded; + auto origValue = appUtils.isMultiProcessModel_.value; + + appUtils.isMultiProcessModel_.isLoaded = true; + appUtils.isMultiProcessModel_.value = false; + + bool result = ChildProcessManager::GetInstance().IsArkChildProcessSupported(); + EXPECT_FALSE(result); + + appUtils.isMultiProcessModel_.isLoaded = origIsLoaded; + appUtils.isMultiProcessModel_.value = origValue; +} + +/** + * @tc.number: IsArkChildProcessSupported_0300 + * @tc.desc: Test IsArkChildProcessSupported when AllowChildProcessInMultiProcessFeatureApp is false + * @tc.type: FUNC + */ +HWTEST_F(ChildProcessManagerTest, IsArkChildProcessSupported_0300, TestSize.Level1) +{ + TAG_LOGD(AAFwkTag::TEST, "IsArkChildProcessSupported_0300 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + auto origIsLoaded = appUtils.isMultiProcessModel_.isLoaded; + auto origValue = appUtils.isMultiProcessModel_.value; + auto origFeatureIsLoaded = appUtils.allowChildProcessInMultiProcessFeatureApp_.isLoaded; + auto origFeatureValue = appUtils.allowChildProcessInMultiProcessFeatureApp_.value; + + appUtils.isMultiProcessModel_.isLoaded = true; + appUtils.isMultiProcessModel_.value = false; + appUtils.allowChildProcessInMultiProcessFeatureApp_.isLoaded = true; + appUtils.allowChildProcessInMultiProcessFeatureApp_.value = false; + + bool result = ChildProcessManager::GetInstance().IsArkChildProcessSupported(); + EXPECT_FALSE(result); + + appUtils.isMultiProcessModel_.isLoaded = origIsLoaded; + appUtils.isMultiProcessModel_.value = origValue; + appUtils.allowChildProcessInMultiProcessFeatureApp_.isLoaded = origFeatureIsLoaded; + appUtils.allowChildProcessInMultiProcessFeatureApp_.value = origFeatureValue; +} + +/** + * @tc.number: IsNativeChildProcessSupported_0100 + * @tc.desc: Test IsNativeChildProcessSupported when MultiProcessModel is enabled + * @tc.type: FUNC + */ +HWTEST_F(ChildProcessManagerTest, IsNativeChildProcessSupported_0100, TestSize.Level1) +{ + TAG_LOGD(AAFwkTag::TEST, "IsNativeChildProcessSupported_0100 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + auto origIsLoaded = appUtils.isMultiProcessModel_.isLoaded; + auto origValue = appUtils.isMultiProcessModel_.value; + + appUtils.isMultiProcessModel_.isLoaded = true; + appUtils.isMultiProcessModel_.value = true; + + bool result = ChildProcessManager::GetInstance().IsNativeChildProcessSupported(); + EXPECT_TRUE(result); + + appUtils.isMultiProcessModel_.isLoaded = origIsLoaded; + appUtils.isMultiProcessModel_.value = origValue; +} + +/** + * @tc.number: IsNativeChildProcessSupported_0200 + * @tc.desc: Test IsNativeChildProcessSupported when MultiProcessModel disabled and GetBundleInfo failed + * @tc.type: FUNC + */ +HWTEST_F(ChildProcessManagerTest, IsNativeChildProcessSupported_0200, TestSize.Level1) +{ + TAG_LOGD(AAFwkTag::TEST, "IsNativeChildProcessSupported_0200 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + auto origIsLoaded = appUtils.isMultiProcessModel_.isLoaded; + auto origValue = appUtils.isMultiProcessModel_.value; + + appUtils.isMultiProcessModel_.isLoaded = true; + appUtils.isMultiProcessModel_.value = false; + + bool result = ChildProcessManager::GetInstance().IsNativeChildProcessSupported(); + EXPECT_FALSE(result); + + appUtils.isMultiProcessModel_.isLoaded = origIsLoaded; + appUtils.isMultiProcessModel_.value = origValue; +} + +/** + * @tc.number: IsNativeChildProcessSupported_0300 + * @tc.desc: Test IsNativeChildProcessSupported when app is not in whitelist and feature app check is false + * @tc.type: FUNC + */ +HWTEST_F(ChildProcessManagerTest, IsNativeChildProcessSupported_0300, TestSize.Level1) +{ + TAG_LOGD(AAFwkTag::TEST, "IsNativeChildProcessSupported_0300 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + auto origIsLoaded = appUtils.isMultiProcessModel_.isLoaded; + auto origValue = appUtils.isMultiProcessModel_.value; + auto origWhitelistIsLoaded = appUtils.allowStartNativeProcessApps_.isLoaded; + auto origFeatureIsLoaded = appUtils.allowChildProcessInMultiProcessFeatureApp_.isLoaded; + auto origFeatureValue = appUtils.allowChildProcessInMultiProcessFeatureApp_.value; + + appUtils.isMultiProcessModel_.isLoaded = true; + appUtils.isMultiProcessModel_.value = false; + appUtils.allowStartNativeProcessApps_.isLoaded = true; + appUtils.allowStartNativeProcessApps_.value = {}; + appUtils.allowChildProcessInMultiProcessFeatureApp_.isLoaded = true; + appUtils.allowChildProcessInMultiProcessFeatureApp_.value = false; + + bool result = ChildProcessManager::GetInstance().IsNativeChildProcessSupported(); + EXPECT_FALSE(result); + + appUtils.isMultiProcessModel_.isLoaded = origIsLoaded; + appUtils.isMultiProcessModel_.value = origValue; + appUtils.allowStartNativeProcessApps_.isLoaded = origWhitelistIsLoaded; + appUtils.allowChildProcessInMultiProcessFeatureApp_.isLoaded = origFeatureIsLoaded; + appUtils.allowChildProcessInMultiProcessFeatureApp_.value = origFeatureValue; +} + +/** + * @tc.number: IsChildProcessSupportedImpl_0100 + * @tc.desc: Test IsChildProcessSupportedImpl with different isNative flags when MultiProcessModel enabled + * @tc.type: FUNC + */ +HWTEST_F(ChildProcessManagerTest, IsChildProcessSupportedImpl_0100, TestSize.Level1) +{ + TAG_LOGD(AAFwkTag::TEST, "IsChildProcessSupportedImpl_0100 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + auto origIsLoaded = appUtils.isMultiProcessModel_.isLoaded; + auto origValue = appUtils.isMultiProcessModel_.value; + + appUtils.isMultiProcessModel_.isLoaded = true; + appUtils.isMultiProcessModel_.value = true; + + auto &cpm = ChildProcessManager::GetInstance(); + bool arkResult = cpm.IsChildProcessSupportedImpl(false); + bool nativeResult = cpm.IsChildProcessSupportedImpl(true); + + EXPECT_TRUE(arkResult); + EXPECT_TRUE(nativeResult); + + appUtils.isMultiProcessModel_.isLoaded = origIsLoaded; + appUtils.isMultiProcessModel_.value = origValue; +} + +/** + * @tc.number: IsChildProcessSupportedImpl_0200 + * @tc.desc: Test IsChildProcessSupportedImpl when GetBundleInfo fails + * @tc.type: FUNC + */ +HWTEST_F(ChildProcessManagerTest, IsChildProcessSupportedImpl_0200, TestSize.Level1) +{ + TAG_LOGD(AAFwkTag::TEST, "IsChildProcessSupportedImpl_0200 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + auto origIsLoaded = appUtils.isMultiProcessModel_.isLoaded; + auto origValue = appUtils.isMultiProcessModel_.value; + + appUtils.isMultiProcessModel_.isLoaded = true; + appUtils.isMultiProcessModel_.value = false; + + auto &cpm = ChildProcessManager::GetInstance(); + bool arkResult = cpm.IsChildProcessSupportedImpl(false); + bool nativeResult = cpm.IsChildProcessSupportedImpl(true); + + EXPECT_FALSE(arkResult); + EXPECT_FALSE(nativeResult); + + appUtils.isMultiProcessModel_.isLoaded = origIsLoaded; + appUtils.isMultiProcessModel_.value = origValue; +} + +/** + * @tc.number: IsChildProcessSupportedImpl_0300 + * @tc.desc: Test IsChildProcessSupportedImpl when AllowChildProcessInMultiProcessFeatureApp is false + * @tc.type: FUNC + */ +HWTEST_F(ChildProcessManagerTest, IsChildProcessSupportedImpl_0300, TestSize.Level1) +{ + TAG_LOGD(AAFwkTag::TEST, "IsChildProcessSupportedImpl_0300 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + auto origIsLoaded = appUtils.isMultiProcessModel_.isLoaded; + auto origValue = appUtils.isMultiProcessModel_.value; + auto origFeatureIsLoaded = appUtils.allowChildProcessInMultiProcessFeatureApp_.isLoaded; + auto origFeatureValue = appUtils.allowChildProcessInMultiProcessFeatureApp_.value; + + appUtils.isMultiProcessModel_.isLoaded = true; + appUtils.isMultiProcessModel_.value = false; + appUtils.allowChildProcessInMultiProcessFeatureApp_.isLoaded = true; + appUtils.allowChildProcessInMultiProcessFeatureApp_.value = false; + + auto &cpm = ChildProcessManager::GetInstance(); + bool arkResult = cpm.IsChildProcessSupportedImpl(false); + bool nativeResult = cpm.IsChildProcessSupportedImpl(true); + + EXPECT_FALSE(arkResult); + EXPECT_FALSE(nativeResult); + + appUtils.isMultiProcessModel_.isLoaded = origIsLoaded; + appUtils.isMultiProcessModel_.value = origValue; + appUtils.allowChildProcessInMultiProcessFeatureApp_.isLoaded = origFeatureIsLoaded; + appUtils.allowChildProcessInMultiProcessFeatureApp_.value = origFeatureValue; +} } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file From 70372242770238e6edc52e8c64145cfef3d5548b Mon Sep 17 00:00:00 2001 From: renjh5496 Date: Mon, 27 Apr 2026 11:24:03 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=B8=8E=E5=88=9B=E5=BB=BA=E5=AD=90?= =?UTF-8?q?=E8=BF=9B=E7=A8=8B=E7=8A=B6=E6=80=81=E4=BF=9D=E6=8C=81=E4=B8=80?= =?UTF-8?q?=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: manual Signed-off-by: renjh5496 --- .../child_process_manager.cpp | 42 +--- frameworks/native/appkit/app/main_thread.cpp | 4 + .../include/appmgr/app_launch_data.h | 22 ++ .../src/appmgr/app_launch_data.cpp | 10 + .../include/child_process_manager.h | 5 +- services/appmgr/include/app_running_record.h | 22 ++ services/appmgr/src/app_mgr_service_inner.cpp | 13 +- services/appmgr/src/app_running_record.cpp | 2 + .../child_process_manager_test.cpp | 210 ++---------------- 9 files changed, 99 insertions(+), 231 deletions(-) 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 4b610080e8..a7a8f833c8 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 @@ -628,47 +628,25 @@ ChildProcessManagerErrorCode ChildProcessManager::KillChildProcessByPid(int32_t } return ChildProcessManagerErrorCode::ERR_OK; } -bool ChildProcessManager::IsChildProcessSupportedImpl(bool isNative) -{ - TAG_LOGD(AAFwkTag::PROCESSMGR, "called"); - if (AAFwk::AppUtils::GetInstance().IsMultiProcessModel()) { - TAG_LOGD(AAFwkTag::PROCESSMGR, "MultiProcessModel enabled, support %{public}s child process", - isNative ? "native" : "ark"); - return true; - } - AppExecFwk::BundleInfo bundleInfo; - bool hasBundleInfo = GetBundleInfo(bundleInfo); - if (!hasBundleInfo) { - TAG_LOGW(AAFwkTag::PROCESSMGR, "Failed to get bundle info"); - return false; - } - if (isNative) { - std::string appIdentifier = bundleInfo.signatureInfo.appIdentifier; - if (!appIdentifier.empty() && AAFwk::AppUtils::GetInstance().IsAllowNativeChildProcess(appIdentifier)) { - TAG_LOGD(AAFwkTag::PROCESSMGR, "App %{public}s in whitelist, support native child process", - bundleInfo.name.c_str()); - return true; - } - } - if (AAFwk::AppUtils::GetInstance().AllowChildProcessInMultiProcessFeatureApp()) { - if (IsMultiProcessFeatureApp(bundleInfo)) { - TAG_LOGD(AAFwkTag::PROCESSMGR, "MultiProcessFeatureApp with large_screen, support %{public}s child process", - isNative ? "native" : "ark"); - return true; - } - } - return false; +void ChildProcessManager::SetArkChildProcessSupported(bool supported) +{ + isArkChildProcessSupported_ = supported; +} + +void ChildProcessManager::SetNativeChildProcessSupported(bool supported) +{ + isNativeChildProcessSupported_ = supported; } bool ChildProcessManager::IsArkChildProcessSupported() { - return IsChildProcessSupportedImpl(false); + return isArkChildProcessSupported_; } bool ChildProcessManager::IsNativeChildProcessSupported() { - return IsChildProcessSupportedImpl(true); + return isNativeChildProcessSupported_; } } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 1458da1193..d5a12eebe3 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -1826,6 +1826,10 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con AbilityRuntime::ChildProcessManager::GetInstance().SetForkProcessDebugOption(appInfo.bundleName, appLaunchData.GetDebugApp(), appInfo.debug, appLaunchData.isNativeStart()); AbilityRuntime::ChildProcessManager::GetInstance().SetApplication(application_); + AbilityRuntime::ChildProcessManager::GetInstance().SetArkChildProcessSupported( + appLaunchData.IsArkChildProcessSupported()); + AbilityRuntime::ChildProcessManager::GetInstance().SetNativeChildProcessSupported( + appLaunchData.IsNativeChildProcessSupported()); #endif // SUPPORT_CHILD_PROCESS if (!pluginBundleInfos.empty()) { for (auto &pluginBundleInfo : pluginBundleInfos) { diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_launch_data.h b/interfaces/inner_api/app_manager/include/appmgr/app_launch_data.h index 7dbb1b45b3..8b61548f47 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_launch_data.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_launch_data.h @@ -368,6 +368,26 @@ public: */ bool GetDebugFromLocal() const; + inline void SetArkChildProcessSupported(bool supported) + { + isArkChildProcessSupported_ = supported; + } + + inline bool IsArkChildProcessSupported() const + { + return isArkChildProcessSupported_; + } + + inline void SetNativeChildProcessSupported(bool supported) + { + isNativeChildProcessSupported_ = supported; + } + + inline bool IsNativeChildProcessSupported() const + { + return isNativeChildProcessSupported_; + } + private: bool debugApp_ = false; bool jitEnabled_ = false; @@ -391,6 +411,8 @@ private: std::string preloadModuleName_; bool isDebugFromLocal_; std::shared_ptr startupTaskData_ = nullptr; + bool isArkChildProcessSupported_ = false; + bool isNativeChildProcessSupported_ = false; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_launch_data.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_launch_data.cpp index edf04370c2..372be89b18 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_launch_data.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_launch_data.cpp @@ -140,6 +140,14 @@ bool AppLaunchData::MarshallingExtend(Parcel &parcel) const TAG_LOGE(AAFwkTag::APPMGR, "Marshalling, Failed to write isDebugFromLocal"); return false; } + if (!parcel.WriteBool(isArkChildProcessSupported_)) { + TAG_LOGE(AAFwkTag::APPMGR, "Marshalling, Failed to write isArkChildProcessSupported"); + return false; + } + if (!parcel.WriteBool(isNativeChildProcessSupported_)) { + TAG_LOGE(AAFwkTag::APPMGR, "Marshalling, Failed to write isNativeChildProcessSupported"); + return false; + } bool hasStartupTaskData = startupTaskData_ ? true : false; if (!parcel.WriteBool(hasStartupTaskData)) { TAG_LOGE(AAFwkTag::APPMGR, "Failed to write the hasStartupTaskData"); @@ -203,6 +211,8 @@ bool AppLaunchData::ReadFromParcel(Parcel &parcel) isAllowedNWebPreload_ = parcel.ReadBool(); preloadModuleName_ = parcel.ReadString(); isDebugFromLocal_ = parcel.ReadBool(); + isArkChildProcessSupported_ = parcel.ReadBool(); + isNativeChildProcessSupported_ = parcel.ReadBool(); if (!ReadStartupTaskDataFromParcel(parcel)) { return false; } 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 41289414a9..e1daabe1a0 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 @@ -46,6 +46,8 @@ public: bool IsChildProcessBySelfFork(); bool IsArkChildProcessSupported(); bool IsNativeChildProcessSupported(); + void SetArkChildProcessSupported(bool supported); + void SetNativeChildProcessSupported(bool supported); ChildProcessManagerErrorCode StartChildProcessBySelfFork(const std::string &srcEntry, pid_t &pid, bool isStaticChildProcess = false); ChildProcessManagerErrorCode StartChildProcessByAppSpawnFork(const std::string &srcEntry, pid_t &pid, @@ -93,12 +95,13 @@ private: sptr GetAppMgr(); void MakeProcessName(const std::string &srcEntry); bool IsMultiProcessFeatureApp(const AppExecFwk::BundleInfo &bundleInfo); - bool IsChildProcessSupportedImpl(bool isNative); ChildProcessManagerErrorCode GetErrorCodeCompat(int32_t ret, int32_t childProcessType); static bool signalRegistered_; bool isChildProcessBySelfFork_ = false; std::atomic childProcessCount_ = 0; + bool isArkChildProcessSupported_ = false; + bool isNativeChildProcessSupported_ = false; mutable std::mutex appMutex_; std::weak_ptr application_; diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index 27c82f68b3..e48fe8e5d8 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -1212,6 +1212,26 @@ public: std::optional IsSupportMultiProcessDeviceFeature() const; void SetSupportMultiProcessDeviceFeature(bool support); + inline void SetArkChildProcessSupported(bool supported) + { + isArkChildProcessSupported_ = supported; + } + + inline bool IsArkChildProcessSupported() const + { + return isArkChildProcessSupported_; + } + + inline void SetNativeChildProcessSupported(bool supported) + { + isNativeChildProcessSupported_ = supported; + } + + inline bool IsNativeChildProcessSupported() const + { + return isNativeChildProcessSupported_; + } + inline void SetMasterProcess(bool isMasterProcess) { isMasterProcess_ = isMasterProcess; @@ -1448,6 +1468,8 @@ private: bool isContinuousTask_ = false; // Only continuesTask processes can be set to true, please choose carefully bool isDebugApp_ = false; bool isDebugFromLocal_ = false; + bool isArkChildProcessSupported_ = false; + bool isNativeChildProcessSupported_ = false; bool isDependedOnArkWeb_ = false; bool isEmptyKeepAliveApp_ = false; // Only empty resident processes can be set to true, please choose carefully bool isErrorInfoEnhance_ = false; diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index c97f4531bb..f5754af291 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -2625,6 +2625,13 @@ void AppMgrServiceInner::LaunchApplicationExt(const std::shared_ptrGetProcessName()); appRecord->SetNWebPreload(isPreload); + bool isMultiProcessModel = AAFwk::AppUtils::GetInstance().IsMultiProcessModel(); + bool isArkSupported = isMultiProcessModel || AllowChildProcessInMultiProcessFeatureApp(appRecord); + bool isNativeSupported = isMultiProcessModel || + AllowNativeChildProcess(CHILD_PROCESS_TYPE_NATIVE, appRecord->GetAppIdentifier()) || + AllowChildProcessInMultiProcessFeatureApp(appRecord); + appRecord->SetArkChildProcessSupported(isArkSupported); + appRecord->SetNativeChildProcessSupported(isNativeSupported); LaunchApplication(appRecord); } @@ -11653,12 +11660,6 @@ int32_t AppMgrServiceInner::CreateNativeChildProcess(const pid_t hostPid, const return ERR_INVALID_OPERATION; } - if (!AllowNativeChildProcess(CHILD_PROCESS_TYPE_NATIVE, appRecord->GetAppIdentifier()) && - !AllowChildProcessInMultiProcessFeatureApp(appRecord)) { - TAG_LOGE(AAFwkTag::APPMGR, "unSupport native child process"); - return AAFwk::ERR_NOT_SUPPORT_NATIVE_CHILD_PROCESS; - } - std::lock_guard lock(childProcessRecordMapMutex_); auto childRecordMap = appRecord->GetChildProcessRecordMap(); auto count = count_if(childRecordMap.begin(), childRecordMap.end(), [] (const auto &pair) -> bool { diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index d9a0e5e228..c7acd0fcad 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -409,6 +409,8 @@ void AppRunningRecord::LaunchApplication(const Configuration &config) launchData.SetNWebPreload(isAllowedNWebPreload_); launchData.SetPreloadModuleName(preloadModuleName_); launchData.SetDebugFromLocal(isDebugFromLocal_); + launchData.SetArkChildProcessSupported(isArkChildProcessSupported_); + launchData.SetNativeChildProcessSupported(isNativeChildProcessSupported_); launchData.SetStartupTaskData(startupTaskData_); launchData.SetImageProcessType(static_cast(imageProcessType_)); 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 4e7cd3fc45..9f60c675cf 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 @@ -685,234 +685,60 @@ HWTEST_F(ChildProcessManagerTest, LoadFromAppRuntime_0300, TestSize.Level2) /** * @tc.number: IsArkChildProcessSupported_0100 - * @tc.desc: Test IsArkChildProcessSupported when MultiProcessModel is enabled + * @tc.desc: Test IsArkChildProcessSupported when supported is set to true * @tc.type: FUNC */ HWTEST_F(ChildProcessManagerTest, IsArkChildProcessSupported_0100, TestSize.Level1) { TAG_LOGD(AAFwkTag::TEST, "IsArkChildProcessSupported_0100 called."); - auto &appUtils = AAFwk::AppUtils::GetInstance(); - auto origIsLoaded = appUtils.isMultiProcessModel_.isLoaded; - auto origValue = appUtils.isMultiProcessModel_.value; - - appUtils.isMultiProcessModel_.isLoaded = true; - appUtils.isMultiProcessModel_.value = true; - - bool result = ChildProcessManager::GetInstance().IsArkChildProcessSupported(); + auto &cpm = ChildProcessManager::GetInstance(); + cpm.SetArkChildProcessSupported(true); + bool result = cpm.IsArkChildProcessSupported(); EXPECT_TRUE(result); - - appUtils.isMultiProcessModel_.isLoaded = origIsLoaded; - appUtils.isMultiProcessModel_.value = origValue; + cpm.SetArkChildProcessSupported(false); } /** * @tc.number: IsArkChildProcessSupported_0200 - * @tc.desc: Test IsArkChildProcessSupported when MultiProcessModel disabled and GetBundleInfo failed + * @tc.desc: Test IsArkChildProcessSupported when supported is set to false * @tc.type: FUNC */ HWTEST_F(ChildProcessManagerTest, IsArkChildProcessSupported_0200, TestSize.Level1) { TAG_LOGD(AAFwkTag::TEST, "IsArkChildProcessSupported_0200 called."); - auto &appUtils = AAFwk::AppUtils::GetInstance(); - auto origIsLoaded = appUtils.isMultiProcessModel_.isLoaded; - auto origValue = appUtils.isMultiProcessModel_.value; - - appUtils.isMultiProcessModel_.isLoaded = true; - appUtils.isMultiProcessModel_.value = false; - - bool result = ChildProcessManager::GetInstance().IsArkChildProcessSupported(); + auto &cpm = ChildProcessManager::GetInstance(); + cpm.SetArkChildProcessSupported(false); + bool result = cpm.IsArkChildProcessSupported(); EXPECT_FALSE(result); - - appUtils.isMultiProcessModel_.isLoaded = origIsLoaded; - appUtils.isMultiProcessModel_.value = origValue; -} - -/** - * @tc.number: IsArkChildProcessSupported_0300 - * @tc.desc: Test IsArkChildProcessSupported when AllowChildProcessInMultiProcessFeatureApp is false - * @tc.type: FUNC - */ -HWTEST_F(ChildProcessManagerTest, IsArkChildProcessSupported_0300, TestSize.Level1) -{ - TAG_LOGD(AAFwkTag::TEST, "IsArkChildProcessSupported_0300 called."); - auto &appUtils = AAFwk::AppUtils::GetInstance(); - auto origIsLoaded = appUtils.isMultiProcessModel_.isLoaded; - auto origValue = appUtils.isMultiProcessModel_.value; - auto origFeatureIsLoaded = appUtils.allowChildProcessInMultiProcessFeatureApp_.isLoaded; - auto origFeatureValue = appUtils.allowChildProcessInMultiProcessFeatureApp_.value; - - appUtils.isMultiProcessModel_.isLoaded = true; - appUtils.isMultiProcessModel_.value = false; - appUtils.allowChildProcessInMultiProcessFeatureApp_.isLoaded = true; - appUtils.allowChildProcessInMultiProcessFeatureApp_.value = false; - - bool result = ChildProcessManager::GetInstance().IsArkChildProcessSupported(); - EXPECT_FALSE(result); - - appUtils.isMultiProcessModel_.isLoaded = origIsLoaded; - appUtils.isMultiProcessModel_.value = origValue; - appUtils.allowChildProcessInMultiProcessFeatureApp_.isLoaded = origFeatureIsLoaded; - appUtils.allowChildProcessInMultiProcessFeatureApp_.value = origFeatureValue; } /** * @tc.number: IsNativeChildProcessSupported_0100 - * @tc.desc: Test IsNativeChildProcessSupported when MultiProcessModel is enabled + * @tc.desc: Test IsNativeChildProcessSupported when supported is set to true * @tc.type: FUNC */ HWTEST_F(ChildProcessManagerTest, IsNativeChildProcessSupported_0100, TestSize.Level1) { TAG_LOGD(AAFwkTag::TEST, "IsNativeChildProcessSupported_0100 called."); - auto &appUtils = AAFwk::AppUtils::GetInstance(); - auto origIsLoaded = appUtils.isMultiProcessModel_.isLoaded; - auto origValue = appUtils.isMultiProcessModel_.value; - - appUtils.isMultiProcessModel_.isLoaded = true; - appUtils.isMultiProcessModel_.value = true; - - bool result = ChildProcessManager::GetInstance().IsNativeChildProcessSupported(); + auto &cpm = ChildProcessManager::GetInstance(); + cpm.SetNativeChildProcessSupported(true); + bool result = cpm.IsNativeChildProcessSupported(); EXPECT_TRUE(result); - - appUtils.isMultiProcessModel_.isLoaded = origIsLoaded; - appUtils.isMultiProcessModel_.value = origValue; + cpm.SetNativeChildProcessSupported(false); } /** * @tc.number: IsNativeChildProcessSupported_0200 - * @tc.desc: Test IsNativeChildProcessSupported when MultiProcessModel disabled and GetBundleInfo failed + * @tc.desc: Test IsNativeChildProcessSupported when supported is set to false * @tc.type: FUNC */ HWTEST_F(ChildProcessManagerTest, IsNativeChildProcessSupported_0200, TestSize.Level1) { TAG_LOGD(AAFwkTag::TEST, "IsNativeChildProcessSupported_0200 called."); - auto &appUtils = AAFwk::AppUtils::GetInstance(); - auto origIsLoaded = appUtils.isMultiProcessModel_.isLoaded; - auto origValue = appUtils.isMultiProcessModel_.value; - - appUtils.isMultiProcessModel_.isLoaded = true; - appUtils.isMultiProcessModel_.value = false; - - bool result = ChildProcessManager::GetInstance().IsNativeChildProcessSupported(); + auto &cpm = ChildProcessManager::GetInstance(); + cpm.SetNativeChildProcessSupported(false); + bool result = cpm.IsNativeChildProcessSupported(); EXPECT_FALSE(result); - - appUtils.isMultiProcessModel_.isLoaded = origIsLoaded; - appUtils.isMultiProcessModel_.value = origValue; -} - -/** - * @tc.number: IsNativeChildProcessSupported_0300 - * @tc.desc: Test IsNativeChildProcessSupported when app is not in whitelist and feature app check is false - * @tc.type: FUNC - */ -HWTEST_F(ChildProcessManagerTest, IsNativeChildProcessSupported_0300, TestSize.Level1) -{ - TAG_LOGD(AAFwkTag::TEST, "IsNativeChildProcessSupported_0300 called."); - auto &appUtils = AAFwk::AppUtils::GetInstance(); - auto origIsLoaded = appUtils.isMultiProcessModel_.isLoaded; - auto origValue = appUtils.isMultiProcessModel_.value; - auto origWhitelistIsLoaded = appUtils.allowStartNativeProcessApps_.isLoaded; - auto origFeatureIsLoaded = appUtils.allowChildProcessInMultiProcessFeatureApp_.isLoaded; - auto origFeatureValue = appUtils.allowChildProcessInMultiProcessFeatureApp_.value; - - appUtils.isMultiProcessModel_.isLoaded = true; - appUtils.isMultiProcessModel_.value = false; - appUtils.allowStartNativeProcessApps_.isLoaded = true; - appUtils.allowStartNativeProcessApps_.value = {}; - appUtils.allowChildProcessInMultiProcessFeatureApp_.isLoaded = true; - appUtils.allowChildProcessInMultiProcessFeatureApp_.value = false; - - bool result = ChildProcessManager::GetInstance().IsNativeChildProcessSupported(); - EXPECT_FALSE(result); - - appUtils.isMultiProcessModel_.isLoaded = origIsLoaded; - appUtils.isMultiProcessModel_.value = origValue; - appUtils.allowStartNativeProcessApps_.isLoaded = origWhitelistIsLoaded; - appUtils.allowChildProcessInMultiProcessFeatureApp_.isLoaded = origFeatureIsLoaded; - appUtils.allowChildProcessInMultiProcessFeatureApp_.value = origFeatureValue; -} - -/** - * @tc.number: IsChildProcessSupportedImpl_0100 - * @tc.desc: Test IsChildProcessSupportedImpl with different isNative flags when MultiProcessModel enabled - * @tc.type: FUNC - */ -HWTEST_F(ChildProcessManagerTest, IsChildProcessSupportedImpl_0100, TestSize.Level1) -{ - TAG_LOGD(AAFwkTag::TEST, "IsChildProcessSupportedImpl_0100 called."); - auto &appUtils = AAFwk::AppUtils::GetInstance(); - auto origIsLoaded = appUtils.isMultiProcessModel_.isLoaded; - auto origValue = appUtils.isMultiProcessModel_.value; - - appUtils.isMultiProcessModel_.isLoaded = true; - appUtils.isMultiProcessModel_.value = true; - - auto &cpm = ChildProcessManager::GetInstance(); - bool arkResult = cpm.IsChildProcessSupportedImpl(false); - bool nativeResult = cpm.IsChildProcessSupportedImpl(true); - - EXPECT_TRUE(arkResult); - EXPECT_TRUE(nativeResult); - - appUtils.isMultiProcessModel_.isLoaded = origIsLoaded; - appUtils.isMultiProcessModel_.value = origValue; -} - -/** - * @tc.number: IsChildProcessSupportedImpl_0200 - * @tc.desc: Test IsChildProcessSupportedImpl when GetBundleInfo fails - * @tc.type: FUNC - */ -HWTEST_F(ChildProcessManagerTest, IsChildProcessSupportedImpl_0200, TestSize.Level1) -{ - TAG_LOGD(AAFwkTag::TEST, "IsChildProcessSupportedImpl_0200 called."); - auto &appUtils = AAFwk::AppUtils::GetInstance(); - auto origIsLoaded = appUtils.isMultiProcessModel_.isLoaded; - auto origValue = appUtils.isMultiProcessModel_.value; - - appUtils.isMultiProcessModel_.isLoaded = true; - appUtils.isMultiProcessModel_.value = false; - - auto &cpm = ChildProcessManager::GetInstance(); - bool arkResult = cpm.IsChildProcessSupportedImpl(false); - bool nativeResult = cpm.IsChildProcessSupportedImpl(true); - - EXPECT_FALSE(arkResult); - EXPECT_FALSE(nativeResult); - - appUtils.isMultiProcessModel_.isLoaded = origIsLoaded; - appUtils.isMultiProcessModel_.value = origValue; -} - -/** - * @tc.number: IsChildProcessSupportedImpl_0300 - * @tc.desc: Test IsChildProcessSupportedImpl when AllowChildProcessInMultiProcessFeatureApp is false - * @tc.type: FUNC - */ -HWTEST_F(ChildProcessManagerTest, IsChildProcessSupportedImpl_0300, TestSize.Level1) -{ - TAG_LOGD(AAFwkTag::TEST, "IsChildProcessSupportedImpl_0300 called."); - auto &appUtils = AAFwk::AppUtils::GetInstance(); - auto origIsLoaded = appUtils.isMultiProcessModel_.isLoaded; - auto origValue = appUtils.isMultiProcessModel_.value; - auto origFeatureIsLoaded = appUtils.allowChildProcessInMultiProcessFeatureApp_.isLoaded; - auto origFeatureValue = appUtils.allowChildProcessInMultiProcessFeatureApp_.value; - - appUtils.isMultiProcessModel_.isLoaded = true; - appUtils.isMultiProcessModel_.value = false; - appUtils.allowChildProcessInMultiProcessFeatureApp_.isLoaded = true; - appUtils.allowChildProcessInMultiProcessFeatureApp_.value = false; - - auto &cpm = ChildProcessManager::GetInstance(); - bool arkResult = cpm.IsChildProcessSupportedImpl(false); - bool nativeResult = cpm.IsChildProcessSupportedImpl(true); - - EXPECT_FALSE(arkResult); - EXPECT_FALSE(nativeResult); - - appUtils.isMultiProcessModel_.isLoaded = origIsLoaded; - appUtils.isMultiProcessModel_.value = origValue; - appUtils.allowChildProcessInMultiProcessFeatureApp_.isLoaded = origFeatureIsLoaded; - appUtils.allowChildProcessInMultiProcessFeatureApp_.value = origFeatureValue; } } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file