diff --git a/frameworks/js/napi/form_provider/js_form_provider.cpp b/frameworks/js/napi/form_provider/js_form_provider.cpp index 097f49a6e6dbf6020074bc24f4cd32a442d51456..d35e72f6b246e5e0626a6050271cbe6a6a6d4dcd 100644 --- a/frameworks/js/napi/form_provider/js_form_provider.cpp +++ b/frameworks/js/napi/form_provider/js_form_provider.cpp @@ -334,7 +334,7 @@ NativeValue *JsFormProvider::OnRequestPublishForm(NativeEngine &engine, NativeCa } convertArgc++; - if (info.argc > ARGS_SIZE_ONE && info.argv[PARAM1]->TypeOf() == NATIVE_OBJECT) { + if (info.argc > ARGS_SIZE_ONE) { asyncCallbackInfo->withFormBindingData = true; if (info.argv[PARAM1]->TypeOf() != NATIVE_OBJECT) { HILOG_ERROR("formBindingData is not napi_object."); diff --git a/interfaces/inner_api/include/form_supply_interface.h b/interfaces/inner_api/include/form_supply_interface.h index a2f461c7cf94f019e11dcd54ed859d7cc81b5abc..645f562169de77938c71a9ae650f7cb4422ad9fe 100644 --- a/interfaces/inner_api/include/form_supply_interface.h +++ b/interfaces/inner_api/include/form_supply_interface.h @@ -75,6 +75,22 @@ public: virtual void OnShareAcquire(int64_t formId, const std::string &remoteDeviceId, const AAFwk::WantParams &wantParams, int64_t requestCode, const bool &result) = 0; + /** + * @brief Accept form render task done from render service. + * @param formId The Id of the form. + * @param want input data. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t OnRenderTaskDone(int64_t formId, const Want &want) = 0; + + /** + * @brief Accept form stop rendering task done from render service. + * @param formId The Id of the form. + * @param want input data. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t OnStopRenderingTaskDone(int64_t formId, const Want &want) = 0; + enum class Message { // ipc id 1-1000 for kit // ipc id 1001-2000 for DMS @@ -84,6 +100,8 @@ public: TRANSACTION_EVENT_HANDLE, TRANSACTION_FORM_STATE_ACQUIRED, TRANSACTION_FORM_SHARE_ACQUIRED, + TRANSACTION_FORM_RENDER_TASK_DONE, + TRANSACTION_FORM_STOP_RENDERING_TASK_DONE, }; }; } // namespace AppExecFwk diff --git a/interfaces/inner_api/include/form_supply_proxy.h b/interfaces/inner_api/include/form_supply_proxy.h index 3a484ecf69517d141bc8e0c5285ab68f7c77a468..9974f1f29f4dfaf70d3b73372539a254350f9edd 100644 --- a/interfaces/inner_api/include/form_supply_proxy.h +++ b/interfaces/inner_api/include/form_supply_proxy.h @@ -71,6 +71,21 @@ public: void OnShareAcquire(int64_t formId, const std::string &remoteDeviceId, const AAFwk::WantParams &wantParams, int64_t requestCode, const bool &result) override; + /** + * @brief Accept form render task done from render service. + * @param formId The Id of the form. + * @param want input data. + * @return Returns ERR_OK on success, others on failure. + */ + int32_t OnRenderTaskDone(int64_t formId, const Want &want) override; + + /** + * @brief Accept form stop rendering task done from render service. + * @param formId The Id of the form. + * @param want input data. + * @return Returns ERR_OK on success, others on failure. + */ + int32_t OnStopRenderingTaskDone(int64_t formId, const Want &want) override; private: template int GetParcelableInfos(MessageParcel &reply, std::vector &parcelableInfos); diff --git a/interfaces/inner_api/include/form_supply_stub.h b/interfaces/inner_api/include/form_supply_stub.h index 68600986602e6d5b832e20dac356ba5c7185a013..7767e5454767147467f33f0e1f08d2d27b079ff8 100644 --- a/interfaces/inner_api/include/form_supply_stub.h +++ b/interfaces/inner_api/include/form_supply_stub.h @@ -70,6 +70,20 @@ private: * @return Returns ERR_OK on success, others on failure. */ int32_t HandleOnShareAcquire(MessageParcel &data, MessageParcel &reply); + /** + * @brief handle OnRenderTaskDone message. + * @param data input param. + * @param reply output param. + * @return Returns ERR_OK on success, others on failure. + */ + int32_t HandleOnRenderTaskDone(MessageParcel &data, MessageParcel &reply); + /** + * @brief handle OnStopRenderingTaskDone message. + * @param data input param. + * @param reply output param. + * @return Returns ERR_OK on success, others on failure. + */ + int32_t HandleOnStopRenderingTaskDone(MessageParcel &data, MessageParcel &reply); private: using FormSupplyFunc = int32_t (FormSupplyStub::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; diff --git a/interfaces/inner_api/src/form_supply_proxy.cpp b/interfaces/inner_api/src/form_supply_proxy.cpp index a87dbad699082163d9a1014aea99c7079bdef7a1..f383688338600c12628bef74804b6137887b33b5 100644 --- a/interfaces/inner_api/src/form_supply_proxy.cpp +++ b/interfaces/inner_api/src/form_supply_proxy.cpp @@ -140,7 +140,6 @@ int FormSupplyProxy::OnAcquireStateResult(FormState state, const std::string &pr return error; } - template int FormSupplyProxy::GetParcelableInfos(MessageParcel &reply, std::vector &parcelableInfos) { @@ -210,5 +209,69 @@ void FormSupplyProxy::OnShareAcquire(int64_t formId, const std::string &remoteDe HILOG_ERROR("failed to SendRequest: %{public}d", error); } } + +int32_t FormSupplyProxy::OnRenderTaskDone(int64_t formId, const Want &want) +{ + MessageParcel data; + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s, failed to write interface token", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + if (!data.WriteInt64(formId)) { + HILOG_ERROR("%{public}s, failed to write formId", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + if (!data.WriteParcelable(&want)) { + HILOG_ERROR("%{public}s, failed to write want", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + MessageParcel reply; + MessageOption option; + int error = Remote()->SendRequest( + static_cast(IFormSupply::Message::TRANSACTION_FORM_RENDER_TASK_DONE), + data, + reply, + option); + if (error != ERR_OK) { + HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error); + } + return error; +} + +int32_t FormSupplyProxy::OnStopRenderingTaskDone(int64_t formId, const Want &want) +{ + MessageParcel data; + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s, failed to write interface token", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + if (!data.WriteInt64(formId)) { + HILOG_ERROR("%{public}s, failed to write formId", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + if (!data.WriteParcelable(&want)) { + HILOG_ERROR("%{public}s, failed to write want", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + MessageParcel reply; + MessageOption option; + int error = Remote()->SendRequest( + static_cast(IFormSupply::Message::TRANSACTION_FORM_STOP_RENDERING_TASK_DONE), + data, + reply, + option); + if (error != ERR_OK) { + HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error); + } + return error; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/src/form_supply_stub.cpp b/interfaces/inner_api/src/form_supply_stub.cpp index 0511a9bda432ffb5068ad861afd5dc2d93a68a2c..72c019824ac9a2532d987df294bb93b2bbe66444 100644 --- a/interfaces/inner_api/src/form_supply_stub.cpp +++ b/interfaces/inner_api/src/form_supply_stub.cpp @@ -36,6 +36,10 @@ FormSupplyStub::FormSupplyStub() &FormSupplyStub::HandleOnAcquireStateResult; memberFuncMap_[static_cast(IFormSupply::Message::TRANSACTION_FORM_SHARE_ACQUIRED)] = &FormSupplyStub::HandleOnShareAcquire; + memberFuncMap_[static_cast(IFormSupply::Message::TRANSACTION_FORM_RENDER_TASK_DONE)] = + &FormSupplyStub::HandleOnRenderTaskDone; + memberFuncMap_[static_cast(IFormSupply::Message::TRANSACTION_FORM_STOP_RENDERING_TASK_DONE)] = + &FormSupplyStub::HandleOnStopRenderingTaskDone; } FormSupplyStub::~FormSupplyStub() @@ -187,5 +191,45 @@ int32_t FormSupplyStub::HandleOnShareAcquire(MessageParcel &data, MessageParcel OnShareAcquire(formId, remoteDeviceId, *wantParams, requestCode, result); return ERR_OK; } + +int32_t FormSupplyStub::HandleOnRenderTaskDone(MessageParcel &data, MessageParcel &reply) +{ + auto formId = data.ReadInt64(); + if (formId <= 0) { + HILOG_ERROR("failed to ReadInt64"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + std::unique_ptr want(data.ReadParcelable()); + if (!want) { + HILOG_ERROR("%{public}s, failed to ReadParcelable", __func__); + reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + int32_t result = OnRenderTaskDone(formId, *want); + reply.WriteInt32(result); + return result; +} + +int32_t FormSupplyStub::HandleOnStopRenderingTaskDone(MessageParcel &data, MessageParcel &reply) +{ + auto formId = data.ReadInt64(); + if (formId <= 0) { + HILOG_ERROR("failed to ReadInt64"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + std::unique_ptr want(data.ReadParcelable()); + if (!want) { + HILOG_ERROR("%{public}s, failed to ReadParcelable", __func__); + reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + int32_t result = OnStopRenderingTaskDone(formId, *want); + reply.WriteInt32(result); + return result; +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/services/form_render_service/BUILD.gn b/services/form_render_service/BUILD.gn old mode 100755 new mode 100644 index fb05eef00da9684402df62fe6439f5a4f3b6dbc3..f8ddbd310a36f3609ed1f7ecfe68c46c368f88f5 --- a/services/form_render_service/BUILD.gn +++ b/services/form_render_service/BUILD.gn @@ -79,7 +79,7 @@ ohos_shared_library("formrender") { "ability_runtime:app_context", "ability_runtime:runtime", "ability_runtime:service_extension", - "ace_engine:ace_uicontent", + "ace_engine:ace_form_render", "bundle_framework:appexecfwk_base", "c_utils:utils", "eventhandler:libeventhandler", diff --git a/services/form_render_service/include/form_render_impl.h b/services/form_render_service/include/form_render_impl.h old mode 100755 new mode 100644 index 83badd1cd0b4d911294ef7440ccdd46d295ff64c..d706891299da1c05254a032a13b5d53a4298556f --- a/services/form_render_service/include/form_render_impl.h +++ b/services/form_render_service/include/form_render_impl.h @@ -25,8 +25,8 @@ #include "event_handler.h" #include "js_runtime.h" #include "runtime.h" -#include "ui_content.h" #include "want.h" +#include "form_renderer_group.h" namespace OHOS { namespace AppExecFwk { @@ -49,14 +49,13 @@ public: const sptr &callerToken) override; /** - * @brief Set the Runtime object - * - * @param runtime The runtime + * @brief Stop rendering form. This is sync API. + * @param formId Indicates The Id of the form to stop rendering. + * @param want Indicates the {@link Want} structure containing form info. + * @param callerToken Caller ability token. + * @return Returns ERR_OK on success, others on failure. */ - void SetRuntime(AbilityRuntime::Runtime& runtime); - int32_t StopRenderingForm(int64_t formId, const Want &want, const sptr &callerToken) override; - private: int32_t AddForm(const FormJsInfo &formJsInfo, const Want &want); void OnActionEvent(const std::string& action) const; @@ -79,27 +78,24 @@ private: std::shared_ptr ObtainEventRunner(const FormJsInfo &formJsInfo); std::shared_ptr CreateEventRunnerLock(const FormJsInfo &formJsInfo); - std::shared_ptr ObtainUIContent( + std::shared_ptr ObtainFormRendererGroup( const FormJsInfo &formJsInfo, const std::shared_ptr &context, const std::shared_ptr &runtime); - std::shared_ptr CreateUIContentLock(const FormJsInfo &formJsInfo, + std::shared_ptr CreateFormRendererGroupLock(const FormJsInfo &formJsInfo, const std::shared_ptr &context, const std::shared_ptr &runtime); private: - static sptr instance_; - int32_t touchTimes_; - bool formInitialized = false; - std::shared_ptr eventHandlerMain_; - std::mutex uiContentMutex_; - std::map> uiContentMap_; // + std::mutex formRendererGroupMutex_; + std::map> formRendererGroupMap_; // std::mutex contextMutex_; std::map> contextMap_; // std::map> shellContextRefMap_; // std::mutex runTimeMutex_; std::map> runTimeMap_; // std::mutex eventRunnerMutex_; + std::map> eventHandlerMap_; // std::map> eventRunnerMap_; // }; -} // namespace FormRender -} // namespace AppExecFwk -} // namespace OHOS -#endif // OHOS_FORM_FWK_FORM_RENDER_IMPL_H +} // namespace FormRender +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_FORM_FWK_FORM_RENDER_IMPL_H diff --git a/services/form_render_service/src/form_render_impl.cpp b/services/form_render_service/src/form_render_impl.cpp old mode 100755 new mode 100644 index 052f9600869c5e0153f4cb0349b67f1f6142a302..09e7ad38132376539aff9c6b714a3b70636db9aa --- a/services/form_render_service/src/form_render_impl.cpp +++ b/services/form_render_service/src/form_render_impl.cpp @@ -24,19 +24,17 @@ #include "form_mgr_errors.h" #include "form_supply_proxy.h" #include "hilog_wrapper.h" -#include "js_context_utils.h" #include "js_runtime.h" -#include "js_runtime_utils.h" #include "service_extension.h" -#include "runtime.h" namespace OHOS { namespace AppExecFwk { namespace FormRender { +namespace { +constexpr int32_t RENDER_FORM_FAILED = -1; +} using namespace AbilityRuntime; -sptr FormRenderImpl::instance_; - static OHOS::AbilityRuntime::ServiceExtension *FormRenderServiceCreator(const std::unique_ptr &runtime) { HILOG_DEBUG("Create FormRenderServiceExtension"); @@ -55,83 +53,264 @@ FormRenderImpl::~FormRenderImpl() = default; int32_t FormRenderImpl::RenderForm(const FormJsInfo &formJsInfo, const Want &want, const sptr &callerToken) { - HILOG_INFO("%{public}s called.", __func__); - return ERR_OK; + HILOG_INFO("Render form, bundleName = %{public}s, abilityName = %{public}s, formName = %{public}s," + "moduleName = %{public}s, jsFormCodePath = %{public}s, formSrc = %{public}s", + formJsInfo.bundleName.c_str(), formJsInfo.abilityName.c_str(), formJsInfo.formName.c_str(), + formJsInfo.moduleName.c_str(), formJsInfo.jsFormCodePath.c_str(), formJsInfo.formSrc.c_str()); + + sptr formSupplyClient = iface_cast(callerToken); + if (formSupplyClient == nullptr) { + HILOG_WARN("%{public}s warn, IFormSupply is nullptr", __func__); + return ERR_APPEXECFWK_FORM_BIND_PROVIDER_FAILED; + } + HILOG_DEBUG("%{public}s come, connectId: %{public}d.", __func__, + want.GetIntParam(Constants::FORM_CONNECT_ID, 0L)); + + int32_t result = ERR_OK; + { + std::lock_guard lock(formRendererGroupMutex_); + if (auto search = formRendererGroupMap_.find(formJsInfo.formId); search == formRendererGroupMap_.end()) { + result = AddForm(formJsInfo, want); + if (result != ERR_OK) { + HILOG_ERROR("Add form failed."); + } + } else { + result = UpdateForm(formJsInfo, want); + } + } + formSupplyClient->OnRenderTaskDone(formJsInfo.formId, want); + return result; } int32_t FormRenderImpl::AddForm(const FormJsInfo &formJsInfo, const Want &want) { - HILOG_INFO("Kee Init form"); + HILOG_INFO("Obtain EventRunner"); + auto runner = ObtainEventRunner(formJsInfo); + if (runner == nullptr) { + HILOG_ERROR("Obtain runtime failed."); + return RENDER_FORM_FAILED; + } + + auto actionEventHandler = [&](const std::string& action) { + OnActionEvent(action); + }; + + auto task = [this, formJsInfo, want, actionEventHandler, runner]() { + HILOG_INFO("Obtain Runtime"); + auto runtime = this->ObtainRuntime(formJsInfo, runner); + if (runtime == nullptr) { + HILOG_ERROR("Obtain runtime failed."); + return; + } + + HILOG_INFO("Obtain context"); + auto context = this->ObtainContext(formJsInfo, runtime); + if (context == nullptr) { + HILOG_ERROR("Obtain context failed."); + return; + } + + { + std::lock_guard lock(this->formRendererGroupMutex_); + if (auto search = this->formRendererGroupMap_.find(formJsInfo.formId); + search != this->formRendererGroupMap_.end()) { + auto group = search->second; + group->UpdateForm(formJsInfo); + return; + } + } + + HILOG_INFO("Obtain FormRenderGroup"); + auto formRendererGroup = this->ObtainFormRendererGroup(formJsInfo, context, runtime); + if (runtime == nullptr) { + HILOG_ERROR("Create formRendererGroup failed."); + return; + } + formRendererGroup->AddForm(want, formJsInfo); + HILOG_INFO("Kee Ace::FormRendererGroup::task over"); + }; + + std::shared_ptr handler = nullptr; + if (auto search = eventHandlerMap_.find(formJsInfo.bundleName); search != eventHandlerMap_.end()) { + handler = search->second; + } + if (handler == nullptr) { + HILOG_ERROR("event handler is nullptr."); + return RENDER_FORM_FAILED; + } + + handler->PostTask(task); + HILOG_ERROR("Kee Ace::FormRendererGroup::OK"); return ERR_OK; } int32_t FormRenderImpl::StopRenderingForm(int64_t formId, const Want &want, const sptr &callerToken) { HILOG_INFO("%{public}s called.", __func__); - return ERR_OK; -} + sptr formSupplyClient = iface_cast(callerToken); + if (formSupplyClient == nullptr) { + HILOG_WARN("%{public}s warn, IFormSupply is nullptr", __func__); + return ERR_APPEXECFWK_FORM_BIND_PROVIDER_FAILED; + } + HILOG_DEBUG("%{public}s come, connectId: %{public}d.", __func__, + want.GetIntParam(Constants::FORM_CONNECT_ID, 0L)); -int32_t FormRenderImpl::UpdateForm(const FormJsInfo &formJsInfo, const Want &want) -{ - HILOG_INFO("Raul update form"); + formSupplyClient->OnStopRenderingTaskDone(formId, want); return ERR_OK; } -void FormRenderImpl::SetRuntime(AbilityRuntime::Runtime& runtime) +int32_t FormRenderImpl::UpdateForm(const FormJsInfo &formJsInfo, const Want &want) { - HILOG_INFO("%{public}s called.", __func__); -} + // start render task + std::shared_ptr sFormRendererGroup = nullptr; + if (auto search = formRendererGroupMap_.find(formJsInfo.formId); search != formRendererGroupMap_.end()) { + sFormRendererGroup = search->second; + } -void FormRenderImpl::OnActionEvent(const std::string& action) const -{ - HILOG_INFO("OnActionEvent: action: %{public}s", action.c_str()); + std::shared_ptr runner = nullptr; + auto key = formJsInfo.bundleName; + if (auto search = eventRunnerMap_.find(key); search != eventRunnerMap_.end()) { + runner = search->second; + } + std::weak_ptr wFormRendererGroup = sFormRendererGroup; + auto task = [wFormRendererGroup, formJsInfo, want]() { + HILOG_INFO("Kee Ace::FormRendererGroup::task, data = %{public}s", formJsInfo.formData.c_str()); + auto formRendererGroup = wFormRendererGroup.lock(); + formRendererGroup->UpdateForm(formJsInfo); + HILOG_INFO("Kee Ace::FormRendererGroup::task over"); + }; + + auto handler = std::make_shared(runner); + if (handler) { + handler->PostTask(task); + } + + HILOG_ERROR("Ace FormRendererGroup OK"); + return ERR_OK; } std::shared_ptr FormRenderImpl::ObtainRuntime(const FormJsInfo &formJsInfo, const std::shared_ptr runner) { - return nullptr; + std::lock_guard lock(runTimeMutex_); + auto key = formJsInfo.bundleName; + if (auto search = runTimeMap_.find(key); search != runTimeMap_.end()) { + return search->second; + } + auto runtime = CreateRuntimeLock(formJsInfo, runner); + if (runtime != nullptr) { + runTimeMap_.emplace(key, runtime); + } + return runtime; } std::shared_ptr FormRenderImpl::CreateRuntimeLock(const FormJsInfo &formJsInfo, const std::shared_ptr runner) { - return nullptr; + AbilityRuntime::Runtime::Options options; + options.bundleName = formJsInfo.bundleName; + options.codePath = Constants::LOCAL_CODE_PATH; + BundleInfo bundleInfo; + options.eventRunner = runner; + options.hapPath = formJsInfo.jsFormCodePath; + options.loadAce = true; + options.isBundle = true; + options.isUnique = true; + auto runtime = AbilityRuntime::Runtime::Create(options); + if (!runtime) { + HILOG_ERROR("create runtime Failed!"); + return nullptr; + } + return runtime; } std::shared_ptr FormRenderImpl::ObtainContext(const FormJsInfo &formJsInfo, const std::shared_ptr &runtime) { - return nullptr; + std::lock_guard lock(contextMutex_); + auto key = formJsInfo.bundleName + formJsInfo.moduleName; + if (auto search = contextMap_.find(key); search != contextMap_.end()) { + return search->second; + } + auto context = CreateContextLock(formJsInfo, runtime); + if (context != nullptr) { + contextMap_.emplace(key, context); + } + return context; } std::shared_ptr FormRenderImpl::CreateContextLock(const FormJsInfo &formJsInfo, const std::shared_ptr &runtime) { - return nullptr; + auto context = std::make_shared(); + if (!context) { + HILOG_ERROR("construct context failed!"); + return nullptr; + } + AppExecFwk::HapModuleInfo hapModuleInfo; + hapModuleInfo.name = formJsInfo.moduleName; + hapModuleInfo.hapPath = formJsInfo.jsFormCodePath; + context->InitHapModuleInfo(hapModuleInfo); + auto applicationInfo = std::make_shared(); + applicationInfo->bundleName = formJsInfo.bundleName; + context->SetApplicationInfo(applicationInfo); + return context; } -std::shared_ptr FormRenderImpl::ObtainUIContent(const FormJsInfo &formJsInfo, +std::shared_ptr FormRenderImpl::ObtainFormRendererGroup(const FormJsInfo &formJsInfo, const std::shared_ptr &context, const std::shared_ptr &runtime) { - return nullptr; + std::lock_guard lock(formRendererGroupMutex_); + auto key = formJsInfo.formId; + if (auto search = formRendererGroupMap_.find(key); search != formRendererGroupMap_.end()) { + return search->second; + } + auto formRendererGroup = CreateFormRendererGroupLock(formJsInfo, context, runtime); + if (formRendererGroup != nullptr) { + formRendererGroupMap_.emplace(key, formRendererGroup); + } + return formRendererGroup; } -std::shared_ptr FormRenderImpl::CreateUIContentLock(const FormJsInfo &formJsInfo, +std::shared_ptr FormRenderImpl::CreateFormRendererGroupLock(const FormJsInfo &formJsInfo, const std::shared_ptr &context, const std::shared_ptr &runtime) { - return nullptr; + auto& nativeEngine = (static_cast(*runtime.get())).GetNativeEngine(); + HILOG_ERROR("Ace formRendererGroup create context_ = %{public}p nativeEngine = %{public}p", + context.get(), &nativeEngine); + auto formRendererGroup = Ace::FormRendererGroup::Create(context, runtime); + if (formRendererGroup == nullptr) { + HILOG_ERROR("Create formRendererGroup failed"); + return nullptr; + } + return formRendererGroup; } std::shared_ptr FormRenderImpl::ObtainEventRunner(const FormJsInfo &formJsInfo) { - return nullptr; + std::lock_guard lock(eventRunnerMutex_); + auto key = formJsInfo.bundleName; + if (auto search = eventRunnerMap_.find(key); search != eventRunnerMap_.end()) { + return search->second; + } + auto eventRunner = CreateEventRunnerLock(formJsInfo); + auto eventHandler = std::make_shared(eventRunner); + if (eventRunner != nullptr) { + eventRunnerMap_.emplace(key, eventRunner); + eventHandlerMap_.emplace(key, eventHandler); + } + return eventRunner; } std::shared_ptr FormRenderImpl::CreateEventRunnerLock(const FormJsInfo &formJsInfo) { - return nullptr; + std::shared_ptr runner = EventRunner::Create(formJsInfo.bundleName); + if (runner == nullptr) { + HILOG_ERROR("create runner Failed."); + return nullptr; + } + return runner; } } // namespace FormRender } // namespace AppExecFwk diff --git a/services/form_render_service/src/form_render_service_extension.cpp b/services/form_render_service/src/form_render_service_extension.cpp index d1d119edde290d6507dcb1cf1ddb1b0d52f8c166..2c77b680e2d2692a95374cd5fbf97522309838f5 100755 --- a/services/form_render_service/src/form_render_service_extension.cpp +++ b/services/form_render_service/src/form_render_service_extension.cpp @@ -76,7 +76,6 @@ sptr FormRenderServiceExtension::OnConnect(const AAFwk::Want &wan AppExecFwk::AbilityTransactionCallbackInfo> *callbackInfo, bool &isAsyncCallback) { HILOG_INFO("%{public}s begin multiParams.", __func__); - OHOS::DelayedSingleton::GetInstance()->SetRuntime(runtime_); return OHOS::DelayedSingleton::GetInstance()->AsObject(); } diff --git a/services/include/form_render_mgr.h b/services/include/form_render_mgr.h index 987d2869e94fbec4bc9e3c0c14d2daee0bcefb89..dd8264e403ce4e251bf265d6932afee03fd63f20 100644 --- a/services/include/form_render_mgr.h +++ b/services/include/form_render_mgr.h @@ -42,9 +42,9 @@ public: ErrCode StopRenderingForm(int64_t formId, const FormRecord &formRecord); - ErrCode RenderFormCallback(int64_t &formId, const Want &want); + ErrCode RenderFormCallback(int64_t formId, const Want &want); - ErrCode StopRenderingFormCallback(int64_t &formId, const Want &want); + ErrCode StopRenderingFormCallback(int64_t formId, const Want &want); ErrCode AddConnection(sptr connection); diff --git a/services/include/form_supply_callback.h b/services/include/form_supply_callback.h index fd3b0a20f2d1796a164eb606a0de15d823f33e54..1752f4ea59b501a13c0869855356316ae0a39f69 100644 --- a/services/include/form_supply_callback.h +++ b/services/include/form_supply_callback.h @@ -82,6 +82,22 @@ public: * @param hostToken Form host proxy object. */ void HandleHostDied(const sptr &hostToken); + + /** + * @brief Accept form render task done from render service. + * @param formId The Id of the form. + * @param want input data. + * @return Returns ERR_OK on success, others on failure. + */ + int32_t OnRenderTaskDone(int64_t formId, const Want &want) override; + + /** + * @brief Accept form stop rendering task done from render service. + * @param formId The Id of the form. + * @param want input data. + * @return Returns ERR_OK on success, others on failure. + */ + int32_t OnStopRenderingTaskDone(int64_t formId, const Want &want) override; private: /** * @brief check if disconnect ability or not. diff --git a/services/src/form_data_mgr.cpp b/services/src/form_data_mgr.cpp index 4338e0419f02e972f048fc73864b1f8ae4cabfab..47b765bac1c4692394970d8b9e2f48ed58fcb487 100644 --- a/services/src/form_data_mgr.cpp +++ b/services/src/form_data_mgr.cpp @@ -203,6 +203,7 @@ void FormDataMgr::CreateFormJsInfo(const int64_t formId, const FormRecord &recor formInfo.versionName = record.versionName; formInfo.compatibleVersion = record.compatibleVersion; formInfo.type = record.type; + formInfo.uiSyntax = record.uiSyntax; } /** * @brief Check temp form count is max. diff --git a/services/src/form_mgr_adapter.cpp b/services/src/form_mgr_adapter.cpp index 2d6d976a73c6a3c0d1ac31c417a254c1a7dce6f0..a7b712dd599dd5bbcd640ba3ff1ac638a307fb21 100644 --- a/services/src/form_mgr_adapter.cpp +++ b/services/src/form_mgr_adapter.cpp @@ -58,6 +58,7 @@ namespace AppExecFwk { namespace { constexpr int32_t CALLING_UID_TRANSFORM_DIVISOR = 200000; constexpr int32_t SYSTEM_UID = 1000; +const std::string POINT_ETS = ".ets"; } // namespace FormMgrAdapter::FormMgrAdapter() diff --git a/services/src/form_render_mgr.cpp b/services/src/form_render_mgr.cpp index 6a7162a6f706da527d94101cf6c002093f42c3c4..03a05e3d8cddf7c4c3e517ff127a5c2b309060c1 100644 --- a/services/src/form_render_mgr.cpp +++ b/services/src/form_render_mgr.cpp @@ -113,7 +113,7 @@ ErrCode FormRenderMgr::StopRenderingForm(int64_t formId, const FormRecord &formR return ERR_OK; } -ErrCode FormRenderMgr::RenderFormCallback(int64_t &formId, const Want &want) +ErrCode FormRenderMgr::RenderFormCallback(int64_t formId, const Want &want) { HILOG_INFO("%{public}s called.", __func__); auto connectId = want.GetIntParam(Constants::FORM_CONNECT_ID, 0); @@ -129,7 +129,7 @@ ErrCode FormRenderMgr::RenderFormCallback(int64_t &formId, const Want &want) return ERR_OK; } -ErrCode FormRenderMgr::StopRenderingFormCallback(int64_t &formId, const Want &want) +ErrCode FormRenderMgr::StopRenderingFormCallback(int64_t formId, const Want &want) { HILOG_INFO("%{public}s called.", __func__); auto connectId = want.GetIntParam(Constants::FORM_CONNECT_ID, 0); diff --git a/services/src/form_supply_callback.cpp b/services/src/form_supply_callback.cpp index 06520954b7835932789a08918f1cad366c16ee5a..b0140ec944a0e2a39d776023ff9b7a5fc7af8521 100644 --- a/services/src/form_supply_callback.cpp +++ b/services/src/form_supply_callback.cpp @@ -282,5 +282,19 @@ void FormSupplyCallback::HandleHostDied(const sptr &hostToken) RemoveConnection(connectId); } } + +int32_t FormSupplyCallback::OnRenderTaskDone(int64_t formId, const Want &want) +{ + HILOG_INFO("%{public}s called.", __func__); + FormRenderMgr::GetInstance().RenderFormCallback(formId, want); + return ERR_OK; +} + +int32_t FormSupplyCallback::OnStopRenderingTaskDone(int64_t formId, const Want &want) +{ + HILOG_INFO("%{public}s called.", __func__); + FormRenderMgr::GetInstance().StopRenderingFormCallback(formId, want); + return ERR_OK; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/fuzztest/formsupplystub_fuzzer/formsupplystub_fuzzer.cpp b/test/fuzztest/formsupplystub_fuzzer/formsupplystub_fuzzer.cpp index 0809f9c69a316bea6e96701af763f3272b599d12..1d2ff1a9f478bcfda0d7b8773b0cc03f2de80464 100755 --- a/test/fuzztest/formsupplystub_fuzzer/formsupplystub_fuzzer.cpp +++ b/test/fuzztest/formsupplystub_fuzzer/formsupplystub_fuzzer.cpp @@ -49,6 +49,14 @@ public: void OnShareAcquire(int64_t formId, const std::string &remoteDeviceId, const AAFwk::WantParams &wantParams, int64_t requestCode, const bool &result) override {} + int32_t OnRenderTaskDone(int64_t formId, const Want &want) override + { + return ERR_OK; + } + int32_t OnStopRenderingTaskDone(int64_t formId, const Want &want) override + { + return ERR_OK; + } }; uint32_t Convert2Uint32(const char* ptr) diff --git a/test/unittest/fms_form_provider_stub_test/fms_form_provider_stub_test.cpp b/test/unittest/fms_form_provider_stub_test/fms_form_provider_stub_test.cpp index c50f7a91f62b993acad89e239eaa17b03d81e357..60412da4feb6065c4a859b6e554e06dcac02fb35 100644 --- a/test/unittest/fms_form_provider_stub_test/fms_form_provider_stub_test.cpp +++ b/test/unittest/fms_form_provider_stub_test/fms_form_provider_stub_test.cpp @@ -100,6 +100,14 @@ public: { return nullptr; }; + int32_t OnRenderTaskDone(int64_t formId, const Want &want) override + { + return ERR_OK; + } + int32_t OnStopRenderingTaskDone(int64_t formId, const Want &want) override + { + return ERR_OK; + } const int number_ = 1; }; /** diff --git a/test/unittest/fms_form_supply_stub_test/fms_form_supply_stub_test.cpp b/test/unittest/fms_form_supply_stub_test/fms_form_supply_stub_test.cpp index 77395a8bd770eb222be5f9e64e149d2f571dcddf..e03051f40334e20fed0f68c37f6a949e275cc078 100644 --- a/test/unittest/fms_form_supply_stub_test/fms_form_supply_stub_test.cpp +++ b/test/unittest/fms_form_supply_stub_test/fms_form_supply_stub_test.cpp @@ -87,6 +87,16 @@ public: const AAFwk::WantParams &wantParams, int64_t requestCode, const bool &result) override {}; + int32_t OnRenderTaskDone(int64_t formId, const Want &want) override + { + return ERR_OK; + } + + int32_t OnStopRenderingTaskDone(int64_t formId, const Want &want) override + { + return ERR_OK; + } + bool asObject_ = true; };