diff --git a/interfaces/innerkits/app_manager/BUILD.gn b/interfaces/innerkits/app_manager/BUILD.gn index ac8817a19cf9d1f06c7f7dcb9d7080d9a2e6a7cd..19ae968ddfd68bb49c7bc0aad4a8be27f77433b3 100644 --- a/interfaces/innerkits/app_manager/BUILD.gn +++ b/interfaces/innerkits/app_manager/BUILD.gn @@ -59,6 +59,8 @@ ohos_shared_library("app_manager") { "src/appmgr/process_data.cpp", "src/appmgr/process_info.cpp", "src/appmgr/profile.cpp", + "src/appmgr/render_scheduler_host.cpp", + "src/appmgr/render_scheduler_proxy.cpp", "src/appmgr/running_process_info.cpp", "src/appmgr/start_specified_ability_response_proxy.cpp", "src/appmgr/start_specified_ability_response_stub.cpp", diff --git a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_client.h b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_client.h index 7680a30963ebfe378772c059c63798279227b7da..432cf349e9e15445f3693e90cd2daebf4748a178 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_client.h +++ b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_client.h @@ -25,6 +25,7 @@ #include "app_mgr_constants.h" #include "bundle_info.h" #include "iapp_state_callback.h" +#include "irender_scheduler.h" #include "running_process_info.h" #include "system_memory_attr.h" #include "istart_specified_ability_response.h" @@ -232,6 +233,25 @@ public: */ virtual int GetAbilityRecordsByProcessID(const int pid, std::vector> &tokens); + /** + * Start webview render process, called by webview host. + * + * @param renderParam, params passed to renderprocess. + * @param ipcFd, ipc file descriptior for web browser and render process. + * @param sharedFd, shared memory file descriptior. + * @param renderPid, created render pid. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int StartRenderProcess(const std::string &renderParam, int32_t ipcFd, + int32_t sharedFd, pid_t &renderPid); + + /** + * Render process call this to attach app manager service. + * + * @param renderScheduler, scheduler of render process. + */ + virtual void AttachRenderProcess(const sptr &renderScheduler); + private: void SetServiceManager(std::unique_ptr serviceMgr); diff --git a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_interface.h index d7a6d9ed61e64e88dc7ed0699de2faad4ad065db..4a34d7ab3906bc4ef2d31a3187b8e85fa1ccdfe3 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_interface.h +++ b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_interface.h @@ -183,6 +183,25 @@ public: */ virtual int GetAbilityRecordsByProcessID(const int pid, std::vector> &tokens) = 0; + /** + * Start webview render process, called by webview host. + * + * @param renderParam, params passed to renderprocess. + * @param ipcFd, ipc file descriptior for web browser and render process. + * @param sharedFd, shared memory file descriptior. + * @param renderPid, created render pid. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int StartRenderProcess(const std::string &renderParam, int32_t ipcFd, + int32_t sharedFd, pid_t &renderPid) = 0; + + /** + * Render process call this to attach app manager service. + * + * @param renderScheduler, scheduler of render process. + */ + virtual void AttachRenderProcess(const sptr &renderScheduler) = 0; + enum class Message { APP_ATTACH_APPLICATION = 0, APP_APPLICATION_FOREGROUNDED, @@ -203,6 +222,8 @@ public: START_USER_TEST_PROCESS, SCHEDULE_ACCEPT_WANT_DONE, APP_GET_ABILITY_RECORDS_BY_PROCESS_ID, + START_RENDER_PROCESS, + ATTACH_RENDER_PROCESS, }; }; } // namespace AppExecFwk diff --git a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_proxy.h b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_proxy.h index 333de1627e232e608c19f032fbc274a44cc7e64e..0a2b53f4384ade47b75f48d32d49a17a60823636 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_proxy.h +++ b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_proxy.h @@ -176,6 +176,25 @@ public: */ virtual int GetAbilityRecordsByProcessID(const int pid, std::vector> &tokens) override; + /** + * Start webview render process, called by webview host. + * + * @param renderParam, params passed to renderprocess. + * @param ipcFd, ipc file descriptior for web browser and render process. + * @param sharedFd, shared memory file descriptior. + * @param renderPid, created render pid. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int StartRenderProcess(const std::string &renderParam, int32_t ipcFd, + int32_t sharedFd, pid_t &renderPid) override; + + /** + * Render process call this to attach app manager service. + * + * @param renderApp, information needed to start the Application. + */ + virtual void AttachRenderProcess(const sptr &renderApp) override; + private: bool SendTransactCmd(IAppMgr::Message code, MessageParcel &data, MessageParcel &reply); bool WriteInterfaceToken(MessageParcel &data); diff --git a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_stub.h b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_stub.h index 9ff9ca280c4783d665264c0354c366dc79af039c..0de454b1fb29db5f01bbb10be53df8bfc4111209 100644 --- a/interfaces/innerkits/app_manager/include/appmgr/app_mgr_stub.h +++ b/interfaces/innerkits/app_manager/include/appmgr/app_mgr_stub.h @@ -74,6 +74,8 @@ private: int32_t HandleStartUserTestProcess(MessageParcel &data, MessageParcel &reply); int32_t HandleScheduleAcceptWantDone(MessageParcel &data, MessageParcel &reply); int32_t HandleGetAbilityRecordsByProcessID(MessageParcel &data, MessageParcel &reply); + int32_t HandleStartRenderProcess(MessageParcel &data, MessageParcel &reply); + int32_t HandleAttachRenderProcess(MessageParcel &data, MessageParcel &reply); using AppMgrFunc = int32_t (AppMgrStub::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; diff --git a/interfaces/innerkits/app_manager/include/appmgr/irender_scheduler.h b/interfaces/innerkits/app_manager/include/appmgr/irender_scheduler.h new file mode 100644 index 0000000000000000000000000000000000000000..d4d7cba7c0d23dbb459d17bd16dd26f4ee9d90b2 --- /dev/null +++ b/interfaces/innerkits/app_manager/include/appmgr/irender_scheduler.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_APPMGR_IRENDER_SCHEDULER_H +#define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_APPMGR_IRENDER_SCHEDULER_H + +#include "iremote_broker.h" + +namespace OHOS { +namespace AppExecFwk { +/** + * @class IRenderScheduler + * Ipc interface of render process to app mgr service. + */ +class IRenderScheduler : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.RenderScheduler"); + + /** + * Notify Browser's fd to render process. + * + * @param ipcFd, ipc file descriptior for web browser and render process. + * @param sharedFd, shared memory file descriptior. + */ + virtual void NotifyBrowserFd(int32_t ipcFd, int32_t sharedFd) = 0; + + enum class Message { + NOTIFY_BROWSER_FD = 1, + }; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_APPMGR_IRENDER_SCHEDULER_H diff --git a/interfaces/innerkits/app_manager/include/appmgr/render_scheduler_host.h b/interfaces/innerkits/app_manager/include/appmgr/render_scheduler_host.h new file mode 100644 index 0000000000000000000000000000000000000000..5b13f250e8a59bdc05fa231cee99b28d8cefea93 --- /dev/null +++ b/interfaces/innerkits/app_manager/include/appmgr/render_scheduler_host.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_APPMGR_RENDER_SCHEDULER_HOST_H +#define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_APPMGR_RENDER_SCHEDULER_HOST_H + +#include + +#include "irender_scheduler.h" +#include "iremote_object.h" +#include "iremote_stub.h" +#include "nocopyable.h" + +namespace OHOS { +namespace AppExecFwk { +/** + * @class RenderSchedulerHost + * RenderScheduler stub. + */ +class RenderSchedulerHost : public IRemoteStub { +public: + RenderSchedulerHost(); + virtual ~RenderSchedulerHost(); + + virtual int OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + int32_t HandleNotifyBrowserFd(MessageParcel &data, MessageParcel &reply); + + using RenderSchedulerFunc = int32_t (RenderSchedulerHost::*)(MessageParcel &data, MessageParcel &reply); + std::map memberFuncMap_; + + DISALLOW_COPY_AND_MOVE(RenderSchedulerHost); +}; +} // namespace AppExecFwk +} // namespace OHOS + +#endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_APPMGR_RENDER_SCHEDULER_HOST_H diff --git a/interfaces/innerkits/app_manager/include/appmgr/render_scheduler_proxy.h b/interfaces/innerkits/app_manager/include/appmgr/render_scheduler_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..196fe3d9d06648c3bf16bb89df9824fca3473f97 --- /dev/null +++ b/interfaces/innerkits/app_manager/include/appmgr/render_scheduler_proxy.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_APPMGR_RENDER_SCHEDULER_PROXY_H +#define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_APPMGR_RENDER_SCHEDULER_PROXY_H + +#include "irender_scheduler.h" + +#include "iremote_proxy.h" + +namespace OHOS { +namespace AppExecFwk { +/** + * @class RenderSchedulerProxy + * RenderScheduler proxy. + */ +class RenderSchedulerProxy : public IRemoteProxy { +public: + explicit RenderSchedulerProxy(const sptr &impl); + + virtual ~RenderSchedulerProxy() = default; + + /** + * Notify Browser's fd to render process. + * + * @param ipcFd, ipc file descriptior for web browser and render process. + * @param sharedFd, shared memory file descriptior. + */ + virtual void NotifyBrowserFd(int32_t ipcFd, int32_t sharedFd) override; + +private: + bool WriteInterfaceToken(MessageParcel &data); + static inline BrokerDelegator delegator_; +}; +} // namespace AppExecFwk +} // namespace OHOS + +#endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_APPMGR_RENDER_SCHEDULER_PROXY_H diff --git a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_client.cpp b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_client.cpp index 8c025af34c9af103e8b223833c78ad598f7d0a95..a3f7aeb832699b096e07f71794ae5fdcdfef02b3 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_client.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_client.cpp @@ -414,5 +414,37 @@ int AppMgrClient::GetAbilityRecordsByProcessID(const int pid, std::vectorGetAbilityRecordsByProcessID(pid, tokens); } + +int AppMgrClient::StartRenderProcess(const std::string &renderParam, int32_t ipcFd, + int32_t sharedFd, pid_t &renderPid) +{ + if (!remote_) { + ConnectAppMgrService(); + } + + sptr service = iface_cast(remote_); + if (service != nullptr) { + return service->StartRenderProcess(renderParam, ipcFd, sharedFd, renderPid); + } + return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; +} + +void AppMgrClient::AttachRenderProcess(const sptr &renderScheduler) +{ + if (!renderScheduler) { + APP_LOGI("renderScheduler is nullptr"); + return; + } + + if (!remote_) { + ConnectAppMgrService(); + } + + sptr service = iface_cast(remote_); + if (service != nullptr) { + APP_LOGI("AttachRenderProcess"); + service->AttachRenderProcess(renderScheduler->AsObject()); + } +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_proxy.cpp b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_proxy.cpp index b8ec6ef84c58c5eabec9c5e4b2b9e2ad7202fd3f..6b36e57d4fc50cf100a2a1b16981c1fbb5394b0a 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_proxy.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_proxy.cpp @@ -537,5 +537,73 @@ int AppMgrProxy::GetAbilityRecordsByProcessID(const int pid, std::vectorSendRequest(static_cast(IAppMgr::Message::START_RENDER_PROCESS), data, reply, option); + if (ret != NO_ERROR) { + APP_LOGW("StartRenderProcess SendRequest is failed, error code: %{public}d", ret); + return ret; + } + + auto result = reply.ReadInt32(); + renderPid = reply.ReadInt32(); + if (result != 0) { + APP_LOGW("StartRenderProcess failed, result: %{public}d", ret); + return ret; + } + return 0; +} + +void AppMgrProxy::AttachRenderProcess(const sptr &renderScheduler) +{ + if (!renderScheduler) { + APP_LOGE("renderScheduler is null"); + return; + } + + APP_LOGD("AttachRenderProcess start"); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + return; + } + if (!data.WriteParcelable(renderScheduler)) { + APP_LOGE("renderScheduler write failed."); + return; + } + + if (!SendTransactCmd(IAppMgr::Message::ATTACH_RENDER_PROCESS, data, reply)) { + APP_LOGE("SendTransactCmd ATTACH_RENDER_PROCESS faild"); + return; + } +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_stub.cpp b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_stub.cpp index 9f932b6024d17253540af7b4a6904f8dbccae831..12bc8d566b0101d617f80c8808b51294c4baf1d7 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_stub.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_stub.cpp @@ -70,6 +70,10 @@ AppMgrStub::AppMgrStub() &AppMgrStub::HandleScheduleAcceptWantDone; memberFuncMap_[static_cast(IAppMgr::Message::APP_GET_ABILITY_RECORDS_BY_PROCESS_ID)] = &AppMgrStub::HandleGetAbilityRecordsByProcessID; + memberFuncMap_[static_cast(IAppMgr::Message::START_RENDER_PROCESS)] = + &AppMgrStub::HandleStartRenderProcess; + memberFuncMap_[static_cast(IAppMgr::Message::ATTACH_RENDER_PROCESS)] = + &AppMgrStub::HandleAttachRenderProcess; } AppMgrStub::~AppMgrStub() @@ -332,5 +336,30 @@ int32_t AppMgrStub::HandleGetAbilityRecordsByProcessID(MessageParcel &data, Mess } return NO_ERROR; } + +int32_t AppMgrStub::HandleStartRenderProcess(MessageParcel &data, MessageParcel &reply) +{ + std::string renderParam = data.ReadString(); + int32_t ipcFd = data.ReadFileDescriptor(); + int32_t sharedFd = data.ReadFileDescriptor(); + int32_t renderPid = 0; + int32_t result = StartRenderProcess(renderParam, ipcFd, sharedFd, renderPid); + if (!reply.WriteInt32(result)) { + APP_LOGE("write result error."); + return ERR_INVALID_VALUE; + } + if (!reply.WriteInt32(renderPid)) { + APP_LOGE("write renderPid error."); + return ERR_INVALID_VALUE; + } + return result; +} + +int32_t AppMgrStub::HandleAttachRenderProcess(MessageParcel &data, MessageParcel &reply) +{ + sptr scheduler = data.ReadParcelable(); + AttachRenderProcess(scheduler); + return NO_ERROR; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/innerkits/app_manager/src/appmgr/render_scheduler_host.cpp b/interfaces/innerkits/app_manager/src/appmgr/render_scheduler_host.cpp new file mode 100644 index 0000000000000000000000000000000000000000..91a2db26d845aa4966508277fab5f0592da0392b --- /dev/null +++ b/interfaces/innerkits/app_manager/src/appmgr/render_scheduler_host.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022 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 "render_scheduler_host.h" + +#include "app_log_wrapper.h" +#include "ipc_types.h" + +namespace OHOS { +namespace AppExecFwk { +RenderSchedulerHost::RenderSchedulerHost() +{ + memberFuncMap_[static_cast(IRenderScheduler::Message::NOTIFY_BROWSER_FD)] = + &RenderSchedulerHost::HandleNotifyBrowserFd; +} + +RenderSchedulerHost::~RenderSchedulerHost() +{ + memberFuncMap_.clear(); +} + +int RenderSchedulerHost::OnRemoteRequest(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + APP_LOGI("RenderSchedulerHost::OnReceived, code = %{public}d, flags= %{public}d.", code, option.GetFlags()); + std::u16string descriptor = RenderSchedulerHost::GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (descriptor != remoteDescriptor) { + APP_LOGE("local descriptor is not equal to remote"); + return ERR_INVALID_STATE; + } + + auto itFunc = memberFuncMap_.find(code); + if (itFunc != memberFuncMap_.end()) { + auto memberFunc = itFunc->second; + if (memberFunc != nullptr) { + return (this->*memberFunc)(data, reply); + } + } + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); +} + +int RenderSchedulerHost::HandleNotifyBrowserFd(MessageParcel &data, MessageParcel &reply) +{ + int32_t ipcFd = data.ReadFileDescriptor(); + int32_t sharedFd = data.ReadFileDescriptor(); + NotifyBrowserFd(ipcFd, sharedFd); + return 0; +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/interfaces/innerkits/app_manager/src/appmgr/render_scheduler_proxy.cpp b/interfaces/innerkits/app_manager/src/appmgr/render_scheduler_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e409655b648f9b964c9333fec3ad12231413dd99 --- /dev/null +++ b/interfaces/innerkits/app_manager/src/appmgr/render_scheduler_proxy.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2022 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 "render_scheduler_proxy.h" + +#include "ipc_types.h" + +#include "app_log_wrapper.h" + +namespace OHOS { +namespace AppExecFwk { +RenderSchedulerProxy::RenderSchedulerProxy( + const sptr &impl) : IRemoteProxy(impl) +{} + +bool RenderSchedulerProxy::WriteInterfaceToken(MessageParcel &data) +{ + if (!data.WriteInterfaceToken(RenderSchedulerProxy::GetDescriptor())) { + APP_LOGE("write interface token failed"); + return false; + } + return true; +} + +void RenderSchedulerProxy::NotifyBrowserFd(int32_t ipcFd, int32_t sharedFd) +{ + APP_LOGD("NotifyBrowserFd start"); + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!WriteInterfaceToken(data)) { + return; + } + + if (!data.WriteFileDescriptor(ipcFd) || !data.WriteFileDescriptor(sharedFd)) { + APP_LOGE("want fd failed, ipcFd:%{public}d, sharedFd:%{public}d", ipcFd, sharedFd); + return; + } + + sptr remote = Remote(); + if (remote == nullptr) { + APP_LOGE("Remote() is NULL"); + return; + } + int32_t ret = remote->SendRequest( + static_cast(IRenderScheduler::Message::NOTIFY_BROWSER_FD), + data, reply, option); + if (ret != NO_ERROR) { + APP_LOGW("SendRequest is failed, error code: %{public}d", ret); + } + APP_LOGD("NotifyBrowserFd end"); +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/ohos.build b/ohos.build index b40f83d76aef96ef371383ff15167b0b0bec7b39..210459f71cf8321a2138e613b7a54586556da773 100644 --- a/ohos.build +++ b/ohos.build @@ -82,7 +82,9 @@ "appmgr/iapp_state_callback.h", "appmgr/app_state_callback_host.h", "appmgr/app_mgr_constants.h", - "appmgr/app_process_data.h" + "appmgr/app_process_data.h", + "appmgr/irender_scheduler.h", + "appmgr/render_scheduler_host.h" ] }, "name": "//foundation/aafwk/standard/interfaces/innerkits/app_manager:app_manager" diff --git a/services/appmgr/include/app_death_recipient.h b/services/appmgr/include/app_death_recipient.h index 39179e0b3a0e9864b882dc210820b8634f83b888..0bd39e48c3ab32105a57d5e14bcacc1ff6ad29ad 100644 --- a/services/appmgr/include/app_death_recipient.h +++ b/services/appmgr/include/app_death_recipient.h @@ -42,7 +42,10 @@ public: */ void SetAppMgrServiceInner(const std::shared_ptr &serviceInner); + void SetIsRenderProcess(bool isRenderProcess); + private: + bool isRenderProcess_ = false; std::weak_ptr handler_; std::weak_ptr appMgrServiceInner_; }; diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index 39cdb8cd1afc6f70e907dd28d3a9b9fd16e12cd0..47eaf0b10628d2471eb8f18fb5c8f592ec1f5293 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -197,6 +197,11 @@ public: */ int GetAbilityRecordsByProcessID(const int pid, std::vector> &tokens) override; + virtual int StartRenderProcess(const std::string &renderParam, int32_t ipcFd, + int32_t sharedFd, pid_t &renderPid) override; + + virtual void AttachRenderProcess(const sptr &shceduler) override; + private: /** * Init, Initialize application services. diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 4a90e67eabc85f6d9c21fd50ff9b2f76b67054cf..d498c3b1a2345a89a1869060089221e9c22487ea 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -391,9 +391,10 @@ public: * OnRemoteDied, Equipment death notification. * * @param remote, Death client. + * @param isRenderProcess is render process died. * @return */ - void OnRemoteDied(const wptr &remote); + void OnRemoteDied(const wptr &remote, bool isRenderProcess = false); /** * AddAppDeathRecipient, Add monitoring death application record. @@ -527,6 +528,11 @@ public: */ int GetAbilityRecordsByProcessID(const int pid, std::vector> &tokens); + virtual int32_t StartRenderProcess(const pid_t hostPid, const std::string &renderParam, + int32_t ipcFd, int32_t sharedFd, pid_t &renderPid); + + virtual void AttachRenderProcess(const pid_t pid, const sptr &scheduler); + private: void StartEmptyResidentProcess(const BundleInfo &info, const std::string &processName, int restartCount); @@ -753,6 +759,11 @@ private: void GetRunningProcesses(const std::shared_ptr &appRecord, std::vector &info); + int StartRenderProcessImpl(const std::shared_ptr &renderRecord, + const std::shared_ptr appRecord, pid_t &renderPid); + + void OnRenderRemoteDied(const wptr &remote); + private: /** * ClearUpApplicationData, clear the application data. diff --git a/services/appmgr/include/app_running_manager.h b/services/appmgr/include/app_running_manager.h index 8d38a1c0b23f1da23b2f05c7aac9468f451f85f4..480fb095df42bb9d8c71075c3847e87bb95b54de 100644 --- a/services/appmgr/include/app_running_manager.h +++ b/services/appmgr/include/app_running_manager.h @@ -148,6 +148,8 @@ public: void ClipStringContent(const std::regex &re, const std::string &sorce, std::string &afferCutStr); void HandleAddAbilityStageTimeOut(const int64_t eventId); void HandleStartSpecifiedAbilityTimeOut(const int64_t eventId); + std::shared_ptr GetAppRunningRecordByRenderPid(const pid_t pid); + void OnRemoteRenderDied(const wptr &remote); private: std::shared_ptr GetAbilityRunningRecord(const int64_t eventId); diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index 3eadad2e2da40477dbc545818c83e0e5800e7293..759010ff9bfaf8e808acac8a8f7799cc856b61dc 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -21,6 +21,7 @@ #include #include #include "iremote_object.h" +#include "irender_scheduler.h" #include "ability_running_record.h" #include "ability_state_data.h" #include "application_info.h" @@ -33,6 +34,7 @@ #include "priority_object.h" #include "app_lifecycle_deal.h" #include "module_running_record.h" +#include "app_spawn_msg_wrapper.h" namespace OHOS { namespace AppExecFwk { @@ -41,6 +43,45 @@ const int RESTART_RESIDENT_PROCESS_MAX_TIMES = 15; } class AbilityRunningRecord; class AppMgrServiceInner; +class AppRunningRecord; + +/** + * @class RenderRecord + * Record webview render process info. + */ +class RenderRecord { +public: + RenderRecord(pid_t hostPid, const std::string& renderParam, + int32_t ipcFd, int32_t sharedFd, const std::shared_ptr &host); + + virtual ~RenderRecord(); + + static std::shared_ptr CreateRenderRecord(pid_t hostPid, const std::string& renderParam, + int32_t ipcFd, int32_t sharedFd, const std::shared_ptr &host); + + void SetPid(pid_t pid); + pid_t GetPid(); + pid_t GetHostPid(); + std::string GetRenderParam(); + int32_t GetIpcFd(); + int32_t GetSharedFd(); + std::shared_ptr GetHostRecord(); + sptr GetScheduler(); + void SetScheduler(const sptr &scheduler); + void SetDeathRecipient(const sptr recipient); + void RegisterDeathRecipient(); + +private: + pid_t pid_ = 0; + pid_t hostPid_ = 0; + std::string renderParam_; + int32_t ipcFd_ = 0; + int32_t sharedFd_ = 0; + std::weak_ptr host_; // webview host + sptr renderScheduler_; + sptr deathRecipient_ = nullptr; +}; + class AppRunningRecord : public std::enable_shared_from_this { public: static int64_t appEventId_; @@ -445,6 +486,11 @@ public: void ScheduleAcceptWantDone(); const AAFwk::Want &GetSpecifiedWant() const; + void SetRenderRecord(const std::shared_ptr &record); + std::shared_ptr GetRenderRecord(); + void SetStartMsg(const AppSpawnStartMsg &msg); + AppSpawnStartMsg GetStartMsg(); + private: /** * SearchTheModuleInfoNeedToUpdated, Get an uninitialized abilitystage data. @@ -523,6 +569,10 @@ private: std::string moduleName_; UserTestRecord userTestRecord_; + + // render record + std::shared_ptr renderRecord_ = nullptr; + AppSpawnStartMsg startMsg_; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/include/app_spawn_client.h b/services/appmgr/include/app_spawn_client.h index 862e80345572bd60bf1a0838b9bd4063119a2a53..96c6cbdba27046306c8b9d65858fd98828835268 100644 --- a/services/appmgr/include/app_spawn_client.h +++ b/services/appmgr/include/app_spawn_client.h @@ -29,7 +29,7 @@ public: /** * Constructor. */ - AppSpawnClient(); + explicit AppSpawnClient(bool isWebViewSpawn = false); /** * Destructor diff --git a/services/appmgr/include/app_spawn_msg_wrapper.h b/services/appmgr/include/app_spawn_msg_wrapper.h index 5415b6385be33acbacc76abaffed44ad3de1503a..acbaeef24d978795a6759501dd11ec1abb369d93 100644 --- a/services/appmgr/include/app_spawn_msg_wrapper.h +++ b/services/appmgr/include/app_spawn_msg_wrapper.h @@ -34,6 +34,7 @@ struct AppSpawnStartMsg { uint32_t accessTokenId; std::string apl; std::string bundleName; + std::string renderParam; // only webview spawn need this param. }; using AppSpawnMsg = AppSpawn::ClientSocket::AppProperty; diff --git a/services/appmgr/include/app_spawn_socket.h b/services/appmgr/include/app_spawn_socket.h index ef133c455abd192461b499a405cbd054df8b95fa..a4c60afa08f60296bf7d822b69cfcf17c07a9930 100644 --- a/services/appmgr/include/app_spawn_socket.h +++ b/services/appmgr/include/app_spawn_socket.h @@ -29,7 +29,7 @@ public: /** * Constructor. */ - AppSpawnSocket(); + explicit AppSpawnSocket(bool isWebViewSpawn = false); /** * Destructor diff --git a/services/appmgr/include/remote_client_manager.h b/services/appmgr/include/remote_client_manager.h index 35656ea55639e172bd943573e30a873e93afac95..1ab9ff8344523f64eab755a8784019f4512366d1 100644 --- a/services/appmgr/include/remote_client_manager.h +++ b/services/appmgr/include/remote_client_manager.h @@ -57,9 +57,12 @@ public: */ void SetBundleManager(sptr bundleManager); + std::shared_ptr GetWebviewSpawnClient(); + private: std::shared_ptr appSpawnClient_; sptr bundleManager_; + std::shared_ptr webviewSpawnClient_; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_death_recipient.cpp b/services/appmgr/src/app_death_recipient.cpp index 9c841c0310a1b08c55678815b701ebe69a1185d9..6ccba58de7f011804bdb2f9fb1a8ec7b93c74372 100644 --- a/services/appmgr/src/app_death_recipient.cpp +++ b/services/appmgr/src/app_death_recipient.cpp @@ -42,7 +42,7 @@ void AppDeathRecipient::OnRemoteDied(const wptr &remote) return; } - std::function onRemoteDiedFunc = std::bind(&AppMgrServiceInner::OnRemoteDied, serviceInner, remote); + auto onRemoteDiedFunc = std::bind(&AppMgrServiceInner::OnRemoteDied, serviceInner, remote, isRenderProcess_); handler->PostTask(onRemoteDiedFunc, TASK_ON_REMOTE_DIED); } @@ -55,5 +55,10 @@ void AppDeathRecipient::SetAppMgrServiceInner(const std::shared_ptrGetAbilityRecordsByProcessID(pid, tokens); } + +int32_t AppMgrService::StartRenderProcess(const std::string &renderParam, int32_t ipcFd, + int32_t sharedFd, pid_t &renderPid) +{ + if (!IsReady()) { + APP_LOGE("StartRenderProcess failed, AppMgrService not ready."); + return ERR_INVALID_OPERATION; + } + + return appMgrServiceInner_->StartRenderProcess(IPCSkeleton::GetCallingPid(), + renderParam, ipcFd, sharedFd, renderPid); +} + +void AppMgrService::AttachRenderProcess(const sptr &scheduler) +{ + APP_LOGD("AttachRenderProcess called."); + if (!IsReady()) { + APP_LOGE("AttachRenderProcess failed, not ready."); + return; + } + + auto pid = IPCSkeleton::GetCallingPid(); + auto fun = std::bind(&AppMgrServiceInner::AttachRenderProcess, + appMgrServiceInner_, pid, iface_cast(scheduler)); + handler_->PostTask(fun, TASK_ATTACH_RENDER_PROCESS); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 8c3f9386320ba1711942cadd858c06afb3fb8682..61b4b47c902f4a072c19ea2aa75e9578ffc1baf0 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -58,6 +58,7 @@ constexpr int KILL_PROCESS_DELAYTIME_MICRO_SECONDS = 200; const std::string CLASS_NAME = "ohos.app.MainThread"; const std::string FUNC_NAME = "main"; const std::string SO_PATH = "system/lib64/libmapleappkit.z.so"; +const std::string RENDER_PARAM = "invalidparam"; const int32_t SIGNAL_KILL = 9; const std::string REQ_PERMISSION = "ohos.permission.LOCATION_IN_BACKGROUND"; constexpr int32_t SYSTEM_UID = 1000; @@ -66,6 +67,9 @@ constexpr int32_t USER_SCALE = 200000; constexpr int32_t BASE_USER_RANGE = 200000; +constexpr ErrCode APPMGR_ERR_OFFSET = ErrCodeOffset(SUBSYS_APPEXECFWK, 0x01); +constexpr ErrCode ERR_ALREADY_EXIST_RENDER = APPMGR_ERR_OFFSET + 100; // error code for already exist render. + int32_t GetUserIdByUid(int32_t uid) { return uid / BASE_USER_RANGE; @@ -1315,6 +1319,7 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str startMsg.accessTokenId = (*bundleInfoIter).applicationInfo.accessTokenId; startMsg.apl = (*bundleInfoIter).applicationInfo.appPrivilegeLevel; startMsg.bundleName = bundleName; + startMsg.renderParam = RENDER_PARAM; APP_LOGD("StartProcess come, accessTokenId: %{public}d, apl: %{public}s, bundleName: %{public}s", startMsg.accessTokenId, startMsg.apl.c_str(), bundleName.c_str()); @@ -1337,6 +1342,7 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str APP_LOGI("newPid:%{public}d uid:%{public}d", pid, startMsg.uid); appRecord->GetPriorityObject()->SetPid(pid); appRecord->SetUid(startMsg.uid); + appRecord->SetStartMsg(startMsg); OptimizerAppStateChanged(appRecord, ApplicationState::APP_STATE_CREATE); appRecord->SetAppMgrServiceInner(weak_from_this()); OnAppStateChanged(appRecord, ApplicationState::APP_STATE_CREATE); @@ -1405,9 +1411,14 @@ void AppMgrServiceInner::ClearRecentAppList() appProcessManager_->ClearRecentAppList(); } -void AppMgrServiceInner::OnRemoteDied(const wptr &remote) +void AppMgrServiceInner::OnRemoteDied(const wptr &remote, bool isRenderProcess) { APP_LOGE("On remote died."); + if (isRenderProcess) { + OnRenderRemoteDied(remote); + return; + } + auto appRecord = appRunningManager_->OnRemoteDied(remote); if (appRecord) { // clear uri permission @@ -1426,6 +1437,13 @@ void AppMgrServiceInner::OnRemoteDied(const wptr &remote) OptimizerAppStateChanged(appRecord, ApplicationState::APP_STATE_TERMINATED); RemoveAppFromRecentListById(appRecord->GetRecordId()); OnProcessDied(appRecord); + + // kill render if exist. + auto renderRecord = appRecord->GetRenderRecord(); + if (renderRecord && renderRecord->GetPid() > 0) { + APP_LOGD("Kill render process when webviehost died."); + KillProcessByPid(renderRecord->GetPid()); + } } if (appRecord && appRecord->IsKeepAliveApp()) { @@ -2315,5 +2333,122 @@ int AppMgrServiceInner::VerifyObserverPermission() APP_LOGE("%{public}s: Permission verification failed", __func__); return ERR_PERMISSION_DENIED; } + +int AppMgrServiceInner::StartRenderProcess(const pid_t hostPid, const std::string &renderParam, + int32_t ipcFd, int32_t sharedFd, pid_t &renderPid) +{ + APP_LOGI("start render process, webview hostpid:%{public}d", hostPid); + if (hostPid <= 0 || renderParam.empty() || ipcFd <= 0 || sharedFd <= 0) { + APP_LOGE("invalid param, hostPid:%{public}d, renderParam:%{public}s, ipcFd:%{public}d, sharedFd:%{public}d", + hostPid, renderParam.c_str(), ipcFd, sharedFd); + return ERR_INVALID_VALUE; + } + + if (!appRunningManager_) { + APP_LOGE("appRunningManager_ is , not start render process"); + return ERR_INVALID_VALUE; + } + + auto appRecord = GetAppRunningRecordByPid(hostPid); + if (!appRecord) { + APP_LOGE("no such appRecord, hostpid:%{public}d", hostPid); + return ERR_INVALID_VALUE; + } + + auto renderRecord = appRecord->GetRenderRecord(); + if (renderRecord) { + APP_LOGW("already exit render process,do not request again, renderPid:%{public}d", renderRecord->GetPid()); + renderPid = renderRecord->GetPid(); + return ERR_ALREADY_EXIST_RENDER; + } + + renderRecord = RenderRecord::CreateRenderRecord(hostPid, renderParam, ipcFd, sharedFd, appRecord); + if (!renderRecord) { + APP_LOGE("create render record failed, hostpid:%{public}d", hostPid); + return ERR_INVALID_VALUE; + } + + return StartRenderProcessImpl(renderRecord, appRecord, renderPid); +} + +void AppMgrServiceInner::AttachRenderProcess(const pid_t pid, const sptr &scheduler) +{ + APP_LOGD("attach render process start"); + if (pid <= 0) { + APP_LOGE("invalid render process pid:%{public}d", pid); + return; + } + if (!scheduler) { + APP_LOGE("render scheduler is null"); + return; + } + + if (!appRunningManager_) { + APP_LOGE("appRunningManager_ is null"); + return; + } + + APP_LOGI("attach render process pid:%{public}d", pid); + auto appRecord = appRunningManager_->GetAppRunningRecordByRenderPid(pid); + if (!appRecord) { + APP_LOGE("no such app Record, pid:%{public}d", pid); + return; + } + + auto renderRecord = appRecord->GetRenderRecord(); + if (!renderRecord) { + APP_LOGE("no such render Record, pid:%{public}d", pid); + return; + } + + sptr appDeathRecipient = new AppDeathRecipient(); + appDeathRecipient->SetEventHandler(eventHandler_); + appDeathRecipient->SetAppMgrServiceInner(shared_from_this()); + appDeathRecipient->SetIsRenderProcess(true); + renderRecord->SetScheduler(scheduler); + renderRecord->SetDeathRecipient(appDeathRecipient); + renderRecord->RegisterDeathRecipient(); + + // notify fd to render process + scheduler->NotifyBrowserFd(renderRecord->GetIpcFd(), renderRecord->GetSharedFd()); +} + +int AppMgrServiceInner::StartRenderProcessImpl(const std::shared_ptr &renderRecord, + const std::shared_ptr appRecord, pid_t &renderPid) +{ + if (!renderRecord || !appRecord) { + APP_LOGE("renderRecord or appRecord is nullptr."); + return ERR_INVALID_VALUE; + } + + auto webviewSpawnClient = remoteClientManager_->GetWebviewSpawnClient(); + if (!webviewSpawnClient) { + APP_LOGE("webviewSpawnClient is null"); + return ERR_INVALID_VALUE; + } + + AppSpawnStartMsg startMsg = appRecord->GetStartMsg(); + startMsg.renderParam = renderRecord->GetRenderParam(); + pid_t pid = 0; + ErrCode errCode = webviewSpawnClient->StartProcess(startMsg, pid); + if (FAILED(errCode)) { + APP_LOGE("failed to spawn new render process, errCode %{public}08x", errCode); + return ERR_INVALID_VALUE; + } + renderPid = pid; + appRecord->SetRenderRecord(renderRecord); + renderRecord->SetPid(pid); + APP_LOGI("start render process successed, hostPid:%{public}d, pid:%{public}d uid:%{public}d", + renderRecord->GetHostPid(), pid, startMsg.uid); + return 0; +} + +void AppMgrServiceInner::OnRenderRemoteDied(const wptr &remote) +{ + APP_LOGE("On render remote died."); + if (appRunningManager_) { + appRunningManager_->OnRemoteRenderDied(remote); + } +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_running_manager.cpp b/services/appmgr/src/app_running_manager.cpp index 3b3c210475a04d361f5f372af89d08f1bfb37b0b..3b0bc1dd4cc3e08029b08bb583a6f5b5e78c6a2f 100644 --- a/services/appmgr/src/app_running_manager.cpp +++ b/services/appmgr/src/app_running_manager.cpp @@ -462,5 +462,48 @@ void AppRunningManager::UpdateConfiguration(const Configuration &config) } } } + +std::shared_ptr AppRunningManager::GetAppRunningRecordByRenderPid(const pid_t pid) +{ + std::lock_guard guard(lock_); + auto iter = std::find_if(appRunningRecordMap_.begin(), appRunningRecordMap_.end(), [&pid](const auto &pair) { + auto renderRecord = pair.second->GetRenderRecord(); + return renderRecord && renderRecord->GetPid() == pid; + }); + return ((iter == appRunningRecordMap_.end()) ? nullptr : iter->second); +} + +void AppRunningManager::OnRemoteRenderDied(const wptr &remote) +{ + std::lock_guard guard(lock_); + if (remote == nullptr) { + APP_LOGE("remote is null"); + return; + } + sptr object = remote.promote(); + if (!object) { + APP_LOGE("promote failed."); + return; + } + + const auto &it = + std::find_if(appRunningRecordMap_.begin(), appRunningRecordMap_.end(), [&object](const auto &pair) { + if (!pair.second) { + return false; + } + + auto renderRecord = pair.second->GetRenderRecord(); + if (!renderRecord) { + return false; + } + + auto scheduler = renderRecord->GetScheduler(); + return scheduler && scheduler->AsObject() == object; + }); + if (it != appRunningRecordMap_.end()) { + auto appRecord = it->second; + appRecord->SetRenderRecord(nullptr); + } +} } // namespace AppExecFwk -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index 827235eb1c80b9b978ce4dbe3ff39d6faa0d4c4c..fceaaec9b47925c303199407a050c3c41721238e 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -21,6 +21,91 @@ namespace OHOS { namespace AppExecFwk { int64_t AppRunningRecord::appEventId_ = 0; + +RenderRecord::RenderRecord(pid_t hostPid, const std::string& renderParam, + int32_t ipcFd, int32_t sharedFd, const std::shared_ptr &host) + : hostPid_(hostPid), renderParam_(renderParam), ipcFd_(ipcFd), sharedFd_(sharedFd), host_(host) +{} + +RenderRecord::~RenderRecord() +{} + +std::shared_ptr RenderRecord::CreateRenderRecord(pid_t hostPid, const std::string& renderParam, + int32_t ipcFd, int32_t sharedFd, const std::shared_ptr &host) +{ + if (hostPid <= 0 || renderParam.empty() || ipcFd <= 0 || sharedFd <= 0 || !host) { + return nullptr; + } + + auto renderRecord = std::make_shared(hostPid, renderParam, ipcFd, sharedFd, host); + if (!renderRecord) { + APP_LOGE("create render record failed, hostPid:%{public}d.", hostPid); + return nullptr; + } + + return renderRecord; +} + +void RenderRecord::SetPid(pid_t pid) +{ + pid_ = pid; +} + +pid_t RenderRecord::GetPid() +{ + return pid_; +} + +pid_t RenderRecord::GetHostPid() +{ + return hostPid_; +} + +std::string RenderRecord::GetRenderParam() +{ + return renderParam_; +} + +int32_t RenderRecord::GetIpcFd() +{ + return ipcFd_; +} + +int32_t RenderRecord::GetSharedFd() +{ + return sharedFd_; +} + +std::shared_ptr RenderRecord::GetHostRecord() +{ + return host_.lock(); +} + +sptr RenderRecord::GetScheduler() +{ + return renderScheduler_; +} + +void RenderRecord::SetScheduler(const sptr &scheduler) +{ + renderScheduler_ = scheduler; +} + +void RenderRecord::SetDeathRecipient(const sptr recipient) +{ + deathRecipient_ = recipient; +} + +void RenderRecord::RegisterDeathRecipient() +{ + if (renderScheduler_ && deathRecipient_) { + auto obj = renderScheduler_->AsObject(); + if (obj) { + obj->AddDeathRecipient(deathRecipient_); + } + } +} + AppRunningRecord::AppRunningRecord( const std::shared_ptr &info, const int32_t recordId, const std::string &processName) : appRecordId_(recordId), processName_(processName) @@ -909,5 +994,25 @@ void AppRunningRecord::UpdateConfiguration(const Configuration &config) } appLifeCycleDeal_->UpdateConfiguration(config); } + +void AppRunningRecord::SetRenderRecord(const std::shared_ptr &record) +{ + renderRecord_ = record; +} + +std::shared_ptr AppRunningRecord::GetRenderRecord() +{ + return renderRecord_; +} + +void AppRunningRecord::SetStartMsg(const AppSpawnStartMsg &msg) +{ + startMsg_ = msg; +} + +AppSpawnStartMsg AppRunningRecord::GetStartMsg() +{ + return startMsg_; +} } // namespace AppExecFwk -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/services/appmgr/src/app_spawn_client.cpp b/services/appmgr/src/app_spawn_client.cpp index 2229827afac0e8e054b1183e63dd9ab0e67671f6..521653972ab1f251bc01164d784f51acccfd81c8 100644 --- a/services/appmgr/src/app_spawn_client.cpp +++ b/services/appmgr/src/app_spawn_client.cpp @@ -25,9 +25,9 @@ const int32_t CONNECT_RETRY_DELAY = 200 * 1000; // 200ms const int32_t CONNECT_RETRY_MAX_TIMES = 15; } // namespace -AppSpawnClient::AppSpawnClient() +AppSpawnClient::AppSpawnClient(bool isWebViewSpawn) { - socket_ = std::make_shared(); + socket_ = std::make_shared(isWebViewSpawn); state_ = SpawnConnectionState::STATE_NOT_CONNECT; } diff --git a/services/appmgr/src/app_spawn_socket.cpp b/services/appmgr/src/app_spawn_socket.cpp index 327b5255cee3cbc79a513c0b3027c839cc3fbb39..4714dd47d1e402dd881e170eb0eb97cd4836d674 100644 --- a/services/appmgr/src/app_spawn_socket.cpp +++ b/services/appmgr/src/app_spawn_socket.cpp @@ -19,11 +19,15 @@ namespace OHOS { namespace AppExecFwk { -// arg "AppSpawn" cannot be defined as string object since REGISTER_SYSTEM_ABILITY will +// arg "AppSpawn" or "WebViewSpawn" cannot be defined as string object since REGISTER_SYSTEM_ABILITY will // firstly start without init this string object, which leads to error. -AppSpawnSocket::AppSpawnSocket() : clientSocket_(std::make_unique("AppSpawn")) -{} +AppSpawnSocket::AppSpawnSocket(bool isWebViewSpawn) +{ + clientSocket_ = isWebViewSpawn ? + std::make_unique("/dev/unix/socket/WebViewSpawn") : + std::make_unique("AppSpawn"); +} AppSpawnSocket::~AppSpawnSocket() {} diff --git a/services/appmgr/src/remote_client_manager.cpp b/services/appmgr/src/remote_client_manager.cpp index 711b395c0d57de2491df62c07cafaf88066a5ff5..8184aa67b9f0f65047e07308d11d6c209501ee1b 100644 --- a/services/appmgr/src/remote_client_manager.cpp +++ b/services/appmgr/src/remote_client_manager.cpp @@ -22,7 +22,8 @@ namespace OHOS { namespace AppExecFwk { -RemoteClientManager::RemoteClientManager() : appSpawnClient_(std::make_shared()) +RemoteClientManager::RemoteClientManager() + : appSpawnClient_(std::make_shared()), webviewSpawnClient_(std::make_shared(true)) {} RemoteClientManager::~RemoteClientManager() @@ -59,5 +60,10 @@ void RemoteClientManager::SetBundleManager(sptr bundleManager) { bundleManager_ = bundleManager; } + +std::shared_ptr RemoteClientManager::GetWebviewSpawnClient() +{ + return webviewSpawnClient_; +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/services/appmgr/test/BUILD.gn b/services/appmgr/test/BUILD.gn index 372b896a424fb82a6898d829726c08c30809ff21..845e14df8fdd7ae77cc8ca7e7ddd927634baee5a 100644 --- a/services/appmgr/test/BUILD.gn +++ b/services/appmgr/test/BUILD.gn @@ -49,6 +49,8 @@ ohos_source_set("appmgr_test_source") { "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/configuration.cpp", "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/process_info.cpp", "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/profile.cpp", + "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/render_scheduler_host.cpp", + "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/render_scheduler_proxy.cpp", "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/running_process_info.cpp", "${appexecfwk_path}/interfaces/innerkits/appexecfwk_base/src/ability_info.cpp", "${appexecfwk_path}/interfaces/innerkits/appexecfwk_base/src/application_info.cpp", diff --git a/services/appmgr/test/mock/include/mock_app_mgr_service.h b/services/appmgr/test/mock/include/mock_app_mgr_service.h index 7c6908a5041dd725bc03e9fb9e857ec0e75d4760..dbd56b7565bd12d64f920a83124a6a28269bcbfb 100644 --- a/services/appmgr/test/mock/include/mock_app_mgr_service.h +++ b/services/appmgr/test/mock/include/mock_app_mgr_service.h @@ -48,6 +48,8 @@ public: MOCK_METHOD2(GetSystemMemoryAttr, void(SystemMemoryAttr &memoryInfo, std::string &strConfig)); MOCK_METHOD0(StartupResidentProcess, void()); MOCK_METHOD1(AddAbilityStageDone, void(const int32_t recordId)); + MOCK_METHOD4(StartRenderProcess, int(const std::string&, int32_t, int32_t, pid_t&)); + MOCK_METHOD1(AttachRenderProcess, void(const sptr &renderScheduler)); MOCK_METHOD1(RegisterApplicationStateObserver, int32_t(const sptr &observer)); MOCK_METHOD1(UnregisterApplicationStateObserver, int32_t(const sptr &observer)); MOCK_METHOD3(ScheduleAcceptWantDone, diff --git a/services/appmgr/test/mock/include/mock_app_spawn_socket.h b/services/appmgr/test/mock/include/mock_app_spawn_socket.h index 4a14ec5ee108c0857ada0934989c1e03131a748a..ea102b63e8e27c3e4a782bfe91be40040c876766 100644 --- a/services/appmgr/test/mock/include/mock_app_spawn_socket.h +++ b/services/appmgr/test/mock/include/mock_app_spawn_socket.h @@ -26,7 +26,7 @@ namespace OHOS { namespace AppExecFwk { class MockAppSpawnSocket : public AppSpawnSocket { public: - MockAppSpawnSocket() = default; + MockAppSpawnSocket() : AppSpawnSocket(false) {} virtual ~MockAppSpawnSocket() = default; MOCK_METHOD0(OpenAppSpawnConnection, ErrCode()); diff --git a/services/appmgr/test/unittest/ams_ability_running_record_test/BUILD.gn b/services/appmgr/test/unittest/ams_ability_running_record_test/BUILD.gn index 7bc452ee09ff2c41b9e4697572b4884251444adb..da2dfe6863f4999cb2b18fb115d419fe35393b3f 100644 --- a/services/appmgr/test/unittest/ams_ability_running_record_test/BUILD.gn +++ b/services/appmgr/test/unittest/ams_ability_running_record_test/BUILD.gn @@ -34,6 +34,7 @@ ohos_unittest("AmsAbilityRunningRecordTest") { sources = [ "${services_path}/appmgr/src/ability_running_record.cpp", + "${services_path}/appmgr/src/app_death_recipient.cpp", "${services_path}/appmgr/src/app_mgr_service_inner.cpp", "${services_path}/appmgr/src/app_running_record.cpp", "${services_path}/appmgr/src/app_spawn_client.cpp", diff --git a/services/appmgr/test/unittest/ams_app_life_cycle_test/BUILD.gn b/services/appmgr/test/unittest/ams_app_life_cycle_test/BUILD.gn index 7e331cba35c3bea973d3a93c3f9d80cfe3919519..1554bc6a97398cab74e5dc4a89811f92a76c54d6 100644 --- a/services/appmgr/test/unittest/ams_app_life_cycle_test/BUILD.gn +++ b/services/appmgr/test/unittest/ams_app_life_cycle_test/BUILD.gn @@ -28,6 +28,7 @@ ohos_unittest("AmsAppLifeCycleTest") { sources = [ "${services_path}/appmgr/src/ability_running_record.cpp", + "${services_path}/appmgr/src/app_death_recipient.cpp", "${services_path}/appmgr/src/app_lifecycle_deal.cpp", "${services_path}/appmgr/src/app_mgr_service_event_handler.cpp", "${services_path}/appmgr/src/app_mgr_service_inner.cpp", diff --git a/services/appmgr/test/unittest/ams_app_running_record_test/BUILD.gn b/services/appmgr/test/unittest/ams_app_running_record_test/BUILD.gn index 3d86925999e1003682e6a40fa598467accf734e4..82442b11ca121637e784796250011340bca2960a 100644 --- a/services/appmgr/test/unittest/ams_app_running_record_test/BUILD.gn +++ b/services/appmgr/test/unittest/ams_app_running_record_test/BUILD.gn @@ -33,6 +33,7 @@ ohos_unittest("AmsAppRunningRecordTest") { sources = [ "${services_path}/appmgr/src/ability_running_record.cpp", + "${services_path}/appmgr/src/app_death_recipient.cpp", "${services_path}/appmgr/src/app_mgr_service_inner.cpp", "${services_path}/appmgr/src/app_running_record.cpp", "${services_path}/appmgr/src/app_spawn_client.cpp", diff --git a/services/appmgr/test/unittest/ams_app_workflow_test/BUILD.gn b/services/appmgr/test/unittest/ams_app_workflow_test/BUILD.gn index a9f9237c6e98421e9f9c2554ce17256362e5155a..254ac523d0364e280ed31f878690769596108989 100644 --- a/services/appmgr/test/unittest/ams_app_workflow_test/BUILD.gn +++ b/services/appmgr/test/unittest/ams_app_workflow_test/BUILD.gn @@ -29,6 +29,7 @@ ohos_unittest("AmsWorkFlowTest") { sources = [ "${services_path}/appmgr/src/ability_running_record.cpp", + "${services_path}/appmgr/src/app_death_recipient.cpp", "${services_path}/appmgr/src/app_lifecycle_deal.cpp", "${services_path}/appmgr/src/app_mgr_service_event_handler.cpp", "${services_path}/appmgr/src/app_mgr_service_inner.cpp", diff --git a/services/appmgr/test/unittest/ams_recent_app_list_test/BUILD.gn b/services/appmgr/test/unittest/ams_recent_app_list_test/BUILD.gn index 0543e6c207d86f97e03abd4969734e0746cae881..49ef60e977f6d32fdadf351ccf2b0d1c72ad3c73 100644 --- a/services/appmgr/test/unittest/ams_recent_app_list_test/BUILD.gn +++ b/services/appmgr/test/unittest/ams_recent_app_list_test/BUILD.gn @@ -27,6 +27,7 @@ ohos_unittest("AmsRecentAppListTest") { sources = [ "${services_path}/appmgr/src/ability_running_record.cpp", + "${services_path}/appmgr/src/app_death_recipient.cpp", "${services_path}/appmgr/src/app_lifecycle_deal.cpp", "${services_path}/appmgr/src/app_mgr_service_inner.cpp", "${services_path}/appmgr/src/app_process_manager.cpp", diff --git a/services/appmgr/test/unittest/ams_service_load_ability_process_test/BUILD.gn b/services/appmgr/test/unittest/ams_service_load_ability_process_test/BUILD.gn index ad1d2e452e80eca448abe88c7c3b600f32511c3e..18c0cf797af5076366d4f98b81952ca2ca73f3a7 100644 --- a/services/appmgr/test/unittest/ams_service_load_ability_process_test/BUILD.gn +++ b/services/appmgr/test/unittest/ams_service_load_ability_process_test/BUILD.gn @@ -27,6 +27,7 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") { sources = [ "${services_path}/appmgr/src/ability_running_record.cpp", + "${services_path}/appmgr/src/app_death_recipient.cpp", "${services_path}/appmgr/src/app_lifecycle_deal.cpp", "${services_path}/appmgr/src/app_mgr_service_inner.cpp", "${services_path}/appmgr/src/app_process_manager.cpp",