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 fcf5e3ceda..fbc06217ca 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..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,5 +628,25 @@ ChildProcessManagerErrorCode ChildProcessManager::KillChildProcessByPid(int32_t } return ChildProcessManagerErrorCode::ERR_OK; } + +void ChildProcessManager::SetArkChildProcessSupported(bool supported) +{ + isArkChildProcessSupported_ = supported; +} + +void ChildProcessManager::SetNativeChildProcessSupported(bool supported) +{ + isNativeChildProcessSupported_ = supported; +} + +bool ChildProcessManager::IsArkChildProcessSupported() +{ + return isArkChildProcessSupported_; +} + +bool ChildProcessManager::IsNativeChildProcessSupported() +{ + 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 8a88cc4230..5f96551921 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -1865,6 +1865,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/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/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 7a86f61f9d..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 @@ -44,6 +44,10 @@ public: static void HandleSigChild(int32_t signo); bool IsChildProcess(); 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, @@ -96,6 +100,8 @@ private: 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/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/include/app_running_record.h b/services/appmgr/include/app_running_record.h index 48eb0f67aa..a4aa9080ce 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -1230,6 +1230,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; @@ -1478,6 +1498,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 daf7bf0dbe..03abe33a06 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -2629,6 +2629,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); } @@ -11708,13 +11715,6 @@ 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()) && - !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 676178d3b2..d480bf06e1 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -417,6 +417,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 3a931be37b..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 @@ -682,5 +682,63 @@ 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 supported is set to true + * @tc.type: FUNC + */ +HWTEST_F(ChildProcessManagerTest, IsArkChildProcessSupported_0100, TestSize.Level1) +{ + TAG_LOGD(AAFwkTag::TEST, "IsArkChildProcessSupported_0100 called."); + auto &cpm = ChildProcessManager::GetInstance(); + cpm.SetArkChildProcessSupported(true); + bool result = cpm.IsArkChildProcessSupported(); + EXPECT_TRUE(result); + cpm.SetArkChildProcessSupported(false); +} + +/** + * @tc.number: IsArkChildProcessSupported_0200 + * @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 &cpm = ChildProcessManager::GetInstance(); + cpm.SetArkChildProcessSupported(false); + bool result = cpm.IsArkChildProcessSupported(); + EXPECT_FALSE(result); +} + +/** + * @tc.number: IsNativeChildProcessSupported_0100 + * @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 &cpm = ChildProcessManager::GetInstance(); + cpm.SetNativeChildProcessSupported(true); + bool result = cpm.IsNativeChildProcessSupported(); + EXPECT_TRUE(result); + cpm.SetNativeChildProcessSupported(false); +} + +/** + * @tc.number: IsNativeChildProcessSupported_0200 + * @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 &cpm = ChildProcessManager::GetInstance(); + cpm.SetNativeChildProcessSupported(false); + bool result = cpm.IsNativeChildProcessSupported(); + EXPECT_FALSE(result); +} } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file