From c6fa13d9f5ec6a89b9d44a8465ba8b31b9fb4cca Mon Sep 17 00:00:00 2001 From: chenliming Date: Sat, 7 Jun 2025 11:16:16 +0800 Subject: [PATCH] =?UTF-8?q?ability=20appMgr=20=E6=8E=A5=E5=8F=A3idl?= =?UTF-8?q?=E5=8C=96=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenliming --- .../native/appkit/app/child_main_thread.cpp | 39 ++++-- interfaces/inner_api/app_manager/BUILD.gn | 113 +++++++++++++++- .../IChildScheduler.idl} | 33 +---- .../appmgr/child_scheduler_interface.h | 51 -------- .../include/appmgr/child_scheduler_stub.h | 46 ------- .../src/appmgr/child_scheduler_proxy.cpp | 121 ------------------ .../src/appmgr/child_scheduler_stub.cpp | 71 ---------- .../native/appkit/app/child_main_thread.h | 8 +- .../appmgr/include/child_process_record.h | 2 +- services/appmgr/src/app_mgr_service_inner.cpp | 5 +- services/appmgr/src/child_process_record.cpp | 3 +- ...rfacesappmgrchildschedulerproxy_fuzzer.cpp | 10 +- ...erfacesappmgrchildschedulerstub_fuzzer.cpp | 26 +++- .../app_mgr_service_inner_eighth_test.cpp | 15 ++- .../app_running_manager_third_test.cpp | 15 ++- .../child_main_thread_first_test.cpp | 16 ++- .../child_main_thread_test.cpp | 16 ++- 17 files changed, 214 insertions(+), 376 deletions(-) rename interfaces/inner_api/app_manager/{include/appmgr/child_scheduler_proxy.h => idl/IChildScheduler.idl} (39%) delete mode 100644 interfaces/inner_api/app_manager/include/appmgr/child_scheduler_interface.h delete mode 100644 interfaces/inner_api/app_manager/include/appmgr/child_scheduler_stub.h delete mode 100644 interfaces/inner_api/app_manager/src/appmgr/child_scheduler_proxy.cpp delete mode 100644 interfaces/inner_api/app_manager/src/appmgr/child_scheduler_stub.cpp diff --git a/frameworks/native/appkit/app/child_main_thread.cpp b/frameworks/native/appkit/app/child_main_thread.cpp index 2b6e24adc0c..5c0b47412b8 100644 --- a/frameworks/native/appkit/app/child_main_thread.cpp +++ b/frameworks/native/appkit/app/child_main_thread.cpp @@ -155,16 +155,18 @@ bool ChildMainThread::Attach() return true; } -bool ChildMainThread::ScheduleLoadChild() +ErrCode ChildMainThread::ScheduleLoadChild(bool& funcResult) { TAG_LOGI(AAFwkTag::APPKIT, "ScheduleLoadChild called"); if (mainHandler_ == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null mainHandler_"); - return false; + funcResult = false; + return AAFwk::INNER_ERR; } if (processInfo_ == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null processInfo"); - return false; + funcResult = false; + return AAFwk::INNER_ERR; } auto childProcessType = processInfo_->childProcessType; wptr weak = this; @@ -184,9 +186,11 @@ bool ChildMainThread::ScheduleLoadChild() }; if (!mainHandler_->PostTask(task, "ChildMainThread::HandleLoadJs")) { TAG_LOGE(AAFwkTag::APPKIT, "postTask task failed"); - return false; + funcResult = false; + return AAFwk::INNER_ERR; } - return true; + funcResult = true; + return ERR_OK; } void ChildMainThread::HandleLoadJs() @@ -310,12 +314,13 @@ void ChildMainThread::ExitProcessSafely() appMgr_->ExitChildProcessSafely(); } -bool ChildMainThread::ScheduleExitProcessSafely() +ErrCode ChildMainThread::ScheduleExitProcessSafely(bool& funcResult) { TAG_LOGD(AAFwkTag::APPKIT, "ScheduleExitProcessSafely"); if (mainHandler_ == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null mainHandler_"); - return false; + funcResult = false; + return AAFwk::INNER_ERR; } wptr weak = this; auto task = [weak]() { @@ -328,9 +333,11 @@ bool ChildMainThread::ScheduleExitProcessSafely() }; if (!mainHandler_->PostTask(task, "ChildMainThread::HandleExitProcessSafely")) { TAG_LOGE(AAFwkTag::APPKIT, "ScheduleExitProcessSafely PostTask task failed"); - return false; + funcResult = false; + return AAFwk::INNER_ERR; } - return true; + funcResult = true; + return ERR_OK; } void ChildMainThread::HandleExitProcessSafely() @@ -347,17 +354,19 @@ void ChildMainThread::HandleExitProcessSafely() } } -bool ChildMainThread::ScheduleRunNativeProc(const sptr &mainProcessCb) +ErrCode ChildMainThread::ScheduleRunNativeProc(const sptr &mainProcessCb, bool& funcResult) { TAG_LOGD(AAFwkTag::APPKIT, "ScheduleRunNativeProc"); if (mainProcessCb == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null mainProcessCb"); - return false; + funcResult = false; + return AAFwk::INNER_ERR; } if (mainHandler_ == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "null mainHandler_"); - return false; + funcResult = false; + return AAFwk::INNER_ERR; } auto task = [weak = wptr(this), callback = sptr(mainProcessCb)]() { @@ -370,9 +379,11 @@ bool ChildMainThread::ScheduleRunNativeProc(const sptr &mainProce }; if (!mainHandler_->PostTask(task, "ChildMainThread::HandleRunNativeProc")) { TAG_LOGE(AAFwkTag::APPKIT, "HandleRunNativeProc PostTask task failed"); - return false; + funcResult = false; + return AAFwk::INNER_ERR; } - return true; + funcResult = true; + return ERR_OK; } void ChildMainThread::HandleRunNativeProc(const sptr &mainProcessCb) diff --git a/interfaces/inner_api/app_manager/BUILD.gn b/interfaces/inner_api/app_manager/BUILD.gn index 70b9b94ddf8..cc378288c38 100644 --- a/interfaces/inner_api/app_manager/BUILD.gn +++ b/interfaces/inner_api/app_manager/BUILD.gn @@ -13,6 +13,13 @@ import("//build/ohos.gni") import("//foundation/ability/ability_runtime/ability_runtime.gni") +import("//build/config/components/idl_tool/idl.gni") + +config("appmgr_idl_config") { + include_dirs = [ + "${target_gen_dir}", + ] +} config("appmgr_sdk_config") { include_dirs = [ @@ -40,7 +47,105 @@ config("appmgr_core_config") { } } +idl_gen_interface("app_mgr_interface") { + sources = [ + "idl/IChildScheduler.idl" + ] + sources_callback = [] + + log_domainid = "0xD001311" + log_tag = "AppMgr" + subsystem_name = "ability" + part_name = "ability_runtime" +} + +ohos_source_set("app_mgr_idl_proxy") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + configs = [ + ":appmgr_core_config", + ":appmgr_sdk_config", + ] + + public_configs = [ + ":appmgr_idl_config", + "${ability_runtime_path}/utils/server/startup:startup_util_config", + ] + + output_values = get_target_outputs(":app_mgr_interface") + sources = filter_include(output_values, [ "*_proxy.cpp" ]) + + deps = [ + ":app_mgr_interface", + "${ability_runtime_path}/utils/server/startup:startup_util", + ] + external_deps = [ + "ability_base:configuration", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + subsystem_name = "ability" + part_name = "ability_runtime" +} + +ohos_source_set("app_mgr_idl_stub") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + configs = [ + ":appmgr_core_config", + ":appmgr_sdk_config", + ] + + public_configs = [ + ":appmgr_idl_config", + "${ability_runtime_path}/utils/server/startup:startup_util_config", + ] + + output_values = get_target_outputs(":app_mgr_interface") + sources = filter_include(output_values, [ "*_stub.cpp" ]) + + deps = [ ":app_mgr_interface" ] + external_deps = [ + "ability_base:configuration", + "ability_base:session_info", + "ability_base:want", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "faultloggerd:libbacktrace_local", + "faultloggerd:libdfx_dumpcatcher", + "faultloggerd:libfaultloggerd", + "ffrt:libffrt", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "image_framework:image_native", + "init:libbegetutil", + "ipc:ipc_core", + "json:nlohmann_json_static", + "relational_store:native_rdb", + "samgr:samgr_proxy", + ] + + subsystem_name = "ability" + part_name = "ability_runtime" +} + ohos_shared_library("app_manager") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } branch_protector_ret = "pac_ret" include_dirs = [ @@ -49,6 +154,7 @@ ohos_shared_library("app_manager") { "${ability_runtime_services_path}/appdfr/include", "${ability_runtime_services_path}/appmgr/include", "${ability_runtime_services_path}/common/include", + "${target_gen_dir}", ] sources = [ @@ -90,8 +196,6 @@ ohos_shared_library("app_manager") { "src/appmgr/application_state_observer_stub.cpp", "src/appmgr/background_app_info.cpp", "src/appmgr/child_process_info.cpp", - "src/appmgr/child_scheduler_proxy.cpp", - "src/appmgr/child_scheduler_stub.cpp", "src/appmgr/configuration_observer_proxy.cpp", "src/appmgr/configuration_observer_stub.cpp", "src/appmgr/configuration_policy.cpp", @@ -127,6 +231,8 @@ ohos_shared_library("app_manager") { public_configs = [ ":appmgr_core_config", ":appmgr_sdk_config", + ":appmgr_idl_config", + "${ability_runtime_path}/utils/server/startup:startup_util_config", ] defines = [ "AMS_LOG_TAG = \"AppexecfwkCore\"" ] @@ -136,6 +242,8 @@ ohos_shared_library("app_manager") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ + ":app_mgr_idl_proxy", + ":app_mgr_idl_stub", "${ability_runtime_path}/utils/global/freeze:freeze_util", "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/common:app_util", @@ -162,6 +270,7 @@ ohos_shared_library("app_manager") { "ability_base:want", "bundle_framework:appexecfwk_base", "image_framework:image_native", + "relational_store:native_dataability", "relational_store:native_rdb", ] if (ability_runtime_child_process) { diff --git a/interfaces/inner_api/app_manager/include/appmgr/child_scheduler_proxy.h b/interfaces/inner_api/app_manager/idl/IChildScheduler.idl similarity index 39% rename from interfaces/inner_api/app_manager/include/appmgr/child_scheduler_proxy.h rename to interfaces/inner_api/app_manager/idl/IChildScheduler.idl index d57785e9617..d3e7bbaa16e 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/child_scheduler_proxy.h +++ b/interfaces/inner_api/app_manager/idl/IChildScheduler.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,29 +13,10 @@ * limitations under the License. */ -#ifndef OHOS_ABILITY_RUNTIME_CHILD_SCHEDULER_PROXY_H -#define OHOS_ABILITY_RUNTIME_CHILD_SCHEDULER_PROXY_H +sequenceable OHOS.IRemoteObject; -#include "child_scheduler_interface.h" - -#include "iremote_proxy.h" - -namespace OHOS { -namespace AppExecFwk { -class ChildSchedulerProxy : public IRemoteProxy { -public: - explicit ChildSchedulerProxy(const sptr &impl); - virtual ~ChildSchedulerProxy() = default; - - bool ScheduleLoadChild() override; - bool ScheduleExitProcessSafely() override; - bool ScheduleRunNativeProc(const sptr &mainProcessCb) override; - -private: - bool WriteInterfaceToken(MessageParcel &data); - static inline BrokerDelegator delegator_; -}; -} // namespace AppExecFwk -} // namespace OHOS - -#endif // OHOS_ABILITY_RUNTIME_CHILD_SCHEDULER_PROXY_H +interface OHOS.AppExecFwk.IChildScheduler { + boolean ScheduleLoadChild(); + boolean ScheduleExitProcessSafely(); + boolean ScheduleRunNativeProc([in] IRemoteObject mainProcessCb); +} \ No newline at end of file diff --git a/interfaces/inner_api/app_manager/include/appmgr/child_scheduler_interface.h b/interfaces/inner_api/app_manager/include/appmgr/child_scheduler_interface.h deleted file mode 100644 index 35ec3c60b70..00000000000 --- a/interfaces/inner_api/app_manager/include/appmgr/child_scheduler_interface.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_ABILITY_RUNTIME_CHILD_SCHEDULER_INTERFACE_H -#define OHOS_ABILITY_RUNTIME_CHILD_SCHEDULER_INTERFACE_H - -#include "iremote_broker.h" - -namespace OHOS { -namespace AppExecFwk { -class IChildScheduler : public IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.ChildScheduler"); - - /** - * Notify chile process to load js file. - */ - virtual bool ScheduleLoadChild() = 0; - - /** - * Notify chile process to exit safely. - */ - virtual bool ScheduleExitProcessSafely() = 0; - - /** - * Notify child process run main proc from shared lib. - * @param mainProcessCb Main process callback ipc object - */ - virtual bool ScheduleRunNativeProc(const sptr &mainProcessCb) = 0; - - enum class Message { - SCHEDULE_LOAD_JS = 0, - SCHEDULE_EXIT_PROCESS_SAFELY = 1, - SCHEDULE_RUN_NATIVE_PROC = 2, - }; -}; -} // namespace AppExecFwk -} // namespace OHOS -#endif // OHOS_ABILITY_RUNTIME_CHILD_SCHEDULER_INTERFACE_H diff --git a/interfaces/inner_api/app_manager/include/appmgr/child_scheduler_stub.h b/interfaces/inner_api/app_manager/include/appmgr/child_scheduler_stub.h deleted file mode 100644 index 02ec8428a1a..00000000000 --- a/interfaces/inner_api/app_manager/include/appmgr/child_scheduler_stub.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless quired by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_ABILITY_RUNTIME_CHILD_SCHEDULER_STUB_H -#define OHOS_ABILITY_RUNTIME_CHILD_SCHEDULER_STUB_H - -#include - -#include "child_scheduler_interface.h" -#include "iremote_object.h" -#include "iremote_stub.h" -#include "nocopyable.h" - -namespace OHOS { -namespace AppExecFwk { -class ChildSchedulerStub : public IRemoteStub { -public: - ChildSchedulerStub(); - virtual ~ChildSchedulerStub(); - - virtual int32_t OnRemoteRequest( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - int32_t HandleScheduleLoadChild(MessageParcel &data, MessageParcel &reply); - int32_t HandleScheduleExitProcessSafely(MessageParcel &data, MessageParcel &reply); - int32_t HandleScheduleRunNativeProc(MessageParcel &data, MessageParcel &reply); - - DISALLOW_COPY_AND_MOVE(ChildSchedulerStub); -}; -} // namespace AppExecFwk -} // namespace OHOS - -#endif // OHOS_ABILITY_RUNTIME_CHILD_SCHEDULER_STUB_H diff --git a/interfaces/inner_api/app_manager/src/appmgr/child_scheduler_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/child_scheduler_proxy.cpp deleted file mode 100644 index 94bddd23a0c..00000000000 --- a/interfaces/inner_api/app_manager/src/appmgr/child_scheduler_proxy.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "child_scheduler_proxy.h" - -#include "hilog_tag_wrapper.h" -#include "ipc_types.h" - -namespace OHOS { -namespace AppExecFwk { -ChildSchedulerProxy::ChildSchedulerProxy(const sptr &impl) : IRemoteProxy(impl) -{} - -bool ChildSchedulerProxy::WriteInterfaceToken(MessageParcel &data) -{ - if (!data.WriteInterfaceToken(ChildSchedulerProxy::GetDescriptor())) { - TAG_LOGE(AAFwkTag::APPMGR, "write interface token failed"); - return false; - } - return true; -} - -bool ChildSchedulerProxy::ScheduleLoadChild() -{ - TAG_LOGD(AAFwkTag::APPMGR, "ScheduleLoadChild start"); - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); - if (!WriteInterfaceToken(data)) { - TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed."); - return false; - } - - sptr remote = Remote(); - if (remote == nullptr) { - TAG_LOGE(AAFwkTag::APPMGR, "Remote() is NULL"); - return false; - } - int32_t ret = remote->SendRequest( - static_cast(IChildScheduler::Message::SCHEDULE_LOAD_JS), data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); - return false; - } - TAG_LOGD(AAFwkTag::APPMGR, "ScheduleLoadChild end"); - return true; -} - -bool ChildSchedulerProxy::ScheduleExitProcessSafely() -{ - TAG_LOGD(AAFwkTag::APPMGR, "ScheduleExitProcessSafely start."); - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); - if (!WriteInterfaceToken(data)) { - TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed."); - return false; - } - - sptr remote = Remote(); - if (remote == nullptr) { - TAG_LOGE(AAFwkTag::APPMGR, "Remote() is NULL."); - return false; - } - int32_t ret = remote->SendRequest( - static_cast(IChildScheduler::Message::SCHEDULE_EXIT_PROCESS_SAFELY), data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d.", ret); - return false; - } - TAG_LOGD(AAFwkTag::APPMGR, "ScheduleExitProcessSafely end."); - return true; -} - -bool ChildSchedulerProxy::ScheduleRunNativeProc(const sptr &mainProcessCb) -{ - TAG_LOGD(AAFwkTag::APPMGR, "ScheduleRunNativeProc start."); - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); - if (!WriteInterfaceToken(data)) { - TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed."); - return false; - } - - if (!data.WriteRemoteObject(mainProcessCb)) { - TAG_LOGE(AAFwkTag::APPMGR, "Write main process callback ipc object failed."); - return false; - } - - sptr remote = Remote(); - if (remote == nullptr) { - TAG_LOGE(AAFwkTag::APPMGR, "Remote() is null."); - return false; - } - - int32_t ret = remote->SendRequest( - static_cast(IChildScheduler::Message::SCHEDULE_RUN_NATIVE_PROC), data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d.", ret); - return false; - } - - TAG_LOGD(AAFwkTag::APPMGR, "ScheduleRunNativeProc end."); - return true; -} - -} // namespace AppExecFwk -} // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/child_scheduler_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/child_scheduler_stub.cpp deleted file mode 100644 index 42e81559dfc..00000000000 --- a/interfaces/inner_api/app_manager/src/appmgr/child_scheduler_stub.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "child_scheduler_stub.h" - -#include "hilog_tag_wrapper.h" -#include "ipc_types.h" - -namespace OHOS { -namespace AppExecFwk { -ChildSchedulerStub::ChildSchedulerStub() {} - -ChildSchedulerStub::~ChildSchedulerStub() {} - -int32_t ChildSchedulerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, - MessageParcel &reply, MessageOption &option) -{ - TAG_LOGI(AAFwkTag::APPMGR, "ChildSchedulerStub::OnReceived, code = %{public}u, flags= %{public}d.", code, - option.GetFlags()); - std::u16string descriptor = ChildSchedulerStub::GetDescriptor(); - std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - TAG_LOGE(AAFwkTag::APPMGR, "A local descriptor is not equivalent to a remote"); - return ERR_INVALID_STATE; - } - - switch (code) { - case static_cast(IChildScheduler::Message::SCHEDULE_LOAD_JS): - return HandleScheduleLoadChild(data, reply); - case static_cast(IChildScheduler::Message::SCHEDULE_EXIT_PROCESS_SAFELY): - return HandleScheduleExitProcessSafely(data, reply); - case static_cast(IChildScheduler::Message::SCHEDULE_RUN_NATIVE_PROC): - return HandleScheduleRunNativeProc(data, reply); - } - TAG_LOGI(AAFwkTag::APPMGR, "ChildSchedulerStub::OnRemoteRequest end"); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); -} - -int32_t ChildSchedulerStub::HandleScheduleLoadChild(MessageParcel &data, MessageParcel &reply) -{ - ScheduleLoadChild(); - return ERR_NONE; -} - -int32_t ChildSchedulerStub::HandleScheduleExitProcessSafely(MessageParcel &data, MessageParcel &reply) -{ - ScheduleExitProcessSafely(); - return ERR_NONE; -} - -int32_t ChildSchedulerStub::HandleScheduleRunNativeProc(MessageParcel &data, MessageParcel &reply) -{ - sptr cb = data.ReadRemoteObject(); - ScheduleRunNativeProc(cb); - return ERR_NONE; -} - -} // namespace AppExecFwk -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/native/appkit/app/child_main_thread.h b/interfaces/kits/native/appkit/app/child_main_thread.h index 17b8d750d85..47455713b68 100644 --- a/interfaces/kits/native/appkit/app/child_main_thread.h +++ b/interfaces/kits/native/appkit/app/child_main_thread.h @@ -24,7 +24,7 @@ #include "base_shared_bundle_info.h" #include "bundle_info.h" #include "bundle_mgr_interface.h" -#include "child_scheduler_interface.h" +#include "ichild_scheduler.h" #include "child_scheduler_stub.h" #ifdef SUPPORT_CHILD_PROCESS #include "child_process_info.h" @@ -42,9 +42,9 @@ class ChildMainThread : public ChildSchedulerStub { public: static void Start(const std::map &fds); void SetFds(const std::map &fds); - bool ScheduleLoadChild() override; - bool ScheduleExitProcessSafely() override; - bool ScheduleRunNativeProc(const sptr &mainProcessCb) override; + ErrCode ScheduleLoadChild(bool& funcResult) override; + ErrCode ScheduleExitProcessSafely(bool& funcResult) override; + ErrCode ScheduleRunNativeProc(const sptr &mainProcessCb, bool& funcResult) override; private: static int32_t GetChildProcessInfo(ChildProcessInfo &info); diff --git a/services/appmgr/include/child_process_record.h b/services/appmgr/include/child_process_record.h index f98c8056d4d..0c177e9bd32 100644 --- a/services/appmgr/include/child_process_record.h +++ b/services/appmgr/include/child_process_record.h @@ -22,7 +22,7 @@ #include "app_death_recipient.h" #include "app_mgr_constants.h" -#include "child_scheduler_interface.h" +#include "ichild_scheduler.h" #include "child_process_info.h" #include "child_process_request.h" diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 711593c788b..c4389f4e26f 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -8385,10 +8385,11 @@ void AppMgrServiceInner::AttachChildProcess(const pid_t pid, const sptrSetDeathRecipient(appDeathRecipient); childRecord->RegisterDeathRecipient(); + bool funcRes = false; if (childRecord->GetChildProcessType() != CHILD_PROCESS_TYPE_NATIVE) { - childScheduler->ScheduleLoadChild(); + childScheduler->ScheduleLoadChild(funcRes); } else { - childScheduler->ScheduleRunNativeProc(childRecord->GetMainProcessCallback()); + childScheduler->ScheduleRunNativeProc(childRecord->GetMainProcessCallback(), funcRes); childRecord->ClearMainProcessCallback(); } } diff --git a/services/appmgr/src/child_process_record.cpp b/services/appmgr/src/child_process_record.cpp index 46f3ed797b8..3bfab03f65c 100644 --- a/services/appmgr/src/child_process_record.cpp +++ b/services/appmgr/src/child_process_record.cpp @@ -177,7 +177,8 @@ void ChildProcessRecord::ScheduleExitProcessSafely() TAG_LOGE(AAFwkTag::APPMGR, "null scheduler_"); return; } - scheduler_->ScheduleExitProcessSafely(); + bool funcRes = false; + scheduler_->ScheduleExitProcessSafely(funcRes); } void ChildProcessRecord::MakeProcessName(const std::shared_ptr hostRecord, diff --git a/test/fuzztest/abilityinterfacesappmgrchildschedulerproxy_fuzzer/abilityinterfacesappmgrchildschedulerproxy_fuzzer.cpp b/test/fuzztest/abilityinterfacesappmgrchildschedulerproxy_fuzzer/abilityinterfacesappmgrchildschedulerproxy_fuzzer.cpp index 22c94da8e72..cbcf2cab81d 100644 --- a/test/fuzztest/abilityinterfacesappmgrchildschedulerproxy_fuzzer/abilityinterfacesappmgrchildschedulerproxy_fuzzer.cpp +++ b/test/fuzztest/abilityinterfacesappmgrchildschedulerproxy_fuzzer/abilityinterfacesappmgrchildschedulerproxy_fuzzer.cpp @@ -20,7 +20,7 @@ #define private public #include "child_scheduler_proxy.h" -#include "child_scheduler_interface.h" +#include "ichild_scheduler.h" #undef private #include "securec.h" @@ -68,15 +68,15 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) { sptr impl; std::shared_ptr infosProxy = std::make_shared(impl); - infosProxy->ScheduleLoadChild(); - infosProxy->ScheduleExitProcessSafely(); + bool funcRes = false; + infosProxy->ScheduleLoadChild(funcRes); + infosProxy->ScheduleExitProcessSafely(funcRes); sptr mainProcessCb; - infosProxy->ScheduleRunNativeProc(mainProcessCb); + infosProxy->ScheduleRunNativeProc(mainProcessCb, funcRes); MessageParcel parcels; parcels.WriteInterfaceToken(AMSMGR_INTERFACE_TOKEN); parcels.WriteBuffer(data, size); parcels.RewindRead(0); - infosProxy->WriteInterfaceToken(parcels); return true; } } diff --git a/test/fuzztest/abilityinterfacesappmgrchildschedulerstub_fuzzer/abilityinterfacesappmgrchildschedulerstub_fuzzer.cpp b/test/fuzztest/abilityinterfacesappmgrchildschedulerstub_fuzzer/abilityinterfacesappmgrchildschedulerstub_fuzzer.cpp index eb204415cd9..17b366baa2f 100644 --- a/test/fuzztest/abilityinterfacesappmgrchildschedulerstub_fuzzer/abilityinterfacesappmgrchildschedulerstub_fuzzer.cpp +++ b/test/fuzztest/abilityinterfacesappmgrchildschedulerstub_fuzzer/abilityinterfacesappmgrchildschedulerstub_fuzzer.cpp @@ -20,7 +20,7 @@ #define private public #include "child_scheduler_stub.h" -#include "child_scheduler_interface.h" +#include "ichild_scheduler.h" #undef private #include "securec.h" @@ -56,9 +56,21 @@ public: virtual ~ ChildSchedulerStubFUZZ() {}; int OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override{ return 0; }; - bool ScheduleLoadChild() override{ return true; }; - bool ScheduleExitProcessSafely() override{ return true; }; - bool ScheduleRunNativeProc(const sptr &mainProcessCb) override{ return true; }; + ErrCode ScheduleLoadChild(bool& funcResult) override + { + funcResult = true; + return ERR_OK; + } + ErrCode ScheduleExitProcessSafely(bool& funcResult) override + { + funcResult = true; + return ERR_OK; + } + ErrCode ScheduleRunNativeProc(const sptr &mainProcessCb, bool& funcResult) override + { + funcResult = true; + return ERR_OK; + } }; sptr GetFuzzAbilityToken() @@ -77,7 +89,7 @@ sptr GetFuzzAbilityToken() bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) { - uint32_t code = static_cast(IChildScheduler::Message::SCHEDULE_LOAD_JS); + uint32_t code = static_cast(IChildSchedulerIpcCode::COMMAND_SCHEDULE_LOAD_CHILD); MessageParcel parcel; parcel.WriteInterfaceToken(CHILD_SCHEDULER_TOKEN); parcel.WriteBuffer(data, size); @@ -86,9 +98,9 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) MessageOption option; std::shared_ptr abms = std::make_shared(); abms->OnRemoteRequest(code, parcel, reply, option); - code = static_cast(IChildScheduler::Message::SCHEDULE_EXIT_PROCESS_SAFELY); + code = static_cast(IChildSchedulerIpcCode::COMMAND_SCHEDULE_EXIT_PROCESS_SAFELY); abms->OnRemoteRequest(code, parcel, reply, option); - code = static_cast(IChildScheduler::Message::SCHEDULE_RUN_NATIVE_PROC); + code = static_cast(IChildSchedulerIpcCode::COMMAND_SCHEDULE_RUN_NATIVE_PROC); abms->OnRemoteRequest(code, parcel, reply, option); return true; } diff --git a/test/unittest/app_mgr_service_inner_eighth_test/app_mgr_service_inner_eighth_test.cpp b/test/unittest/app_mgr_service_inner_eighth_test/app_mgr_service_inner_eighth_test.cpp index a76ce33ce28..ecdb563a1f3 100644 --- a/test/unittest/app_mgr_service_inner_eighth_test/app_mgr_service_inner_eighth_test.cpp +++ b/test/unittest/app_mgr_service_inner_eighth_test/app_mgr_service_inner_eighth_test.cpp @@ -74,18 +74,21 @@ public: }; class MyChildScheduler : public IChildScheduler { public: - bool ScheduleLoadChild() override + ErrCode ScheduleLoadChild(bool& funcResult) override { g_scheduleLoadChildCall++; - return false; + funcResult = false; + return ERR_OK; } - bool ScheduleExitProcessSafely() override + ErrCode ScheduleExitProcessSafely(bool& funcResult) override { - return false; + funcResult = false; + return ERR_OK; } - bool ScheduleRunNativeProc(const sptr &mainProcessCb) override + ErrCode ScheduleRunNativeProc(const sptr &mainProcessCb, bool& funcResult) override { - return false; + funcResult = false; + return ERR_OK; } sptr AsObject() override { diff --git a/test/unittest/app_running_manager_third_test/app_running_manager_third_test.cpp b/test/unittest/app_running_manager_third_test/app_running_manager_third_test.cpp index 34fb80f4561..3fba6b001ea 100644 --- a/test/unittest/app_running_manager_third_test/app_running_manager_third_test.cpp +++ b/test/unittest/app_running_manager_third_test/app_running_manager_third_test.cpp @@ -90,19 +90,22 @@ class MockIChildScheduler : public IChildScheduler { public: MockIChildScheduler() = default; ~MockIChildScheduler() = default; - bool ScheduleLoadChild() override + ErrCode ScheduleLoadChild(bool &funcRes) override { - return true; + funcRes = true; + return ERR_OK; } - bool ScheduleExitProcessSafely() override + ErrCode ScheduleExitProcessSafely(bool &funcRes) override { - return true; + funcRes = true; + return ERR_OK; } - bool ScheduleRunNativeProc(const sptr &mainProcessCb) override + ErrCode ScheduleRunNativeProc(const sptr &mainProcessCb, bool &funcRes) override { - return true; + funcRes = true; + return ERR_OK; } sptr AsObject() override diff --git a/test/unittest/appkit/child_main_thread_first_test/child_main_thread_first_test.cpp b/test/unittest/appkit/child_main_thread_first_test/child_main_thread_first_test.cpp index 083fc9297ab..bde6a281054 100644 --- a/test/unittest/appkit/child_main_thread_first_test/child_main_thread_first_test.cpp +++ b/test/unittest/appkit/child_main_thread_first_test/child_main_thread_first_test.cpp @@ -92,8 +92,9 @@ HWTEST_F(ChildMainThreadFirstTest, ScheduleLoadChild_0100, TestSize.Level1) thread_->mainHandler_ = handler; thread_->processInfo_ = std::make_shared(); - auto ret = thread_->ScheduleLoadChild(); - EXPECT_TRUE(ret); + bool funcRes = false; + thread_->ScheduleLoadChild(funcRes); + EXPECT_TRUE(funcRes); TAG_LOGI(AAFwkTag::TEST, "ScheduleLoadChild_0100 end."); } @@ -106,8 +107,10 @@ HWTEST_F(ChildMainThreadFirstTest, ScheduleLoadChild_0200, TestSize.Level1) { TAG_LOGI(AAFwkTag::TEST, "ScheduleLoadChild_0200 start."); ASSERT_NE(thread_, nullptr); - auto ret = thread_->ScheduleLoadChild(); - EXPECT_FALSE(ret); + + bool funcRes = false; + thread_->ScheduleLoadChild(funcRes); + EXPECT_FALSE(funcRes); TAG_LOGI(AAFwkTag::TEST, "ScheduleLoadChild_0200 end."); } @@ -123,8 +126,9 @@ HWTEST_F(ChildMainThreadFirstTest, ScheduleLoadChild_0300, TestSize.Level1) std::shared_ptr runner = EventRunner::GetMainEventRunner(); std::shared_ptr handler = std::make_shared(runner); thread_->mainHandler_ = handler; - auto ret = thread_->ScheduleLoadChild(); - EXPECT_FALSE(ret); + bool funcRes = false; + thread_->ScheduleLoadChild(funcRes); + EXPECT_FALSE(funcRes); TAG_LOGI(AAFwkTag::TEST, "ScheduleLoadChild_0300 end."); } diff --git a/test/unittest/appkit/child_main_thread_test/child_main_thread_test.cpp b/test/unittest/appkit/child_main_thread_test/child_main_thread_test.cpp index bd054a6b0e6..1c01374c391 100644 --- a/test/unittest/appkit/child_main_thread_test/child_main_thread_test.cpp +++ b/test/unittest/appkit/child_main_thread_test/child_main_thread_test.cpp @@ -113,9 +113,9 @@ HWTEST_F(ChildMainThreadTest, ScheduleLoadChild_0100, TestSize.Level1) std::shared_ptr handler = std::make_shared(runner); thread->mainHandler_ = handler; thread->processInfo_ = std::make_shared(); - - auto ret = thread->ScheduleLoadChild(); - EXPECT_TRUE(ret); + bool funcRes = false; + thread->ScheduleLoadChild(funcRes); + EXPECT_TRUE(funcRes); } /** @@ -202,8 +202,9 @@ HWTEST_F(ChildMainThreadTest, ScheduleExitProcessSafely_0100, TestSize.Level2) std::shared_ptr handler = std::make_shared(runner); thread->mainHandler_ = handler; - auto ret = thread->ScheduleExitProcessSafely(); - EXPECT_TRUE(ret); + bool funcRes = false; + thread->ScheduleExitProcessSafely(funcRes); + EXPECT_TRUE(funcRes); } /** @@ -222,8 +223,9 @@ HWTEST_F(ChildMainThreadTest, ScheduleRunNativeProc_0100, TestSize.Level2) thread->mainHandler_ = handler; sptr mainPorcessCb = nullptr; - auto ret = thread->ScheduleRunNativeProc(mainPorcessCb); - EXPECT_FALSE(ret); + bool funcRes = false; + thread->ScheduleRunNativeProc(mainPorcessCb, funcRes); + EXPECT_FALSE(funcRes); } } // namespace AppExecFwk -- Gitee